Class LogRecordJson

java.lang.Object
codes.grow.packages.betterstack.logging.LogRecordJson

public final class LogRecordJson extends Object
Converts LogRecord to and from the normalized JSON wire form ( spec/schemas/log-record.schema.json).

Fields: timestamp and the optional observedTimestamp (RFC 3339 UTC, nanosecond precision), severity (OTel number), severityText, body, attributes, resource and the optional traceId, spanId, traceFlags.

  • Method Details

    • toMap

      public static Map<String,Object> toMap(LogRecord record)
      Returns the wire form as an ordered map of plain JSON values.
      Parameters:
      record - the record
      Returns:
      an ordered map
    • toJson

      public static String toJson(LogRecord record)
      Serialises a record to compact JSON.
      Parameters:
      record - the record
      Returns:
      JSON text
    • byteSize

      public static int byteSize(LogRecord record)
      Returns the UTF-8 size of the record's JSON form (the unit of maxBatchBytes).
      Parameters:
      record - the record
      Returns:
      size in bytes
    • fromJson

      public static LogRecord fromJson(String json)
      Parses one record from JSON text.
      Parameters:
      json - JSON object text
      Returns:
      the record
      Throws:
      ValidationException - when the JSON is not a valid record
    • fromJsonNode

      public static LogRecord fromJsonNode(com.fasterxml.jackson.databind.JsonNode node)
      Parses one record from a Jackson tree. Unknown fields are ignored; a non-string body is JSON-encoded; severity may be a number (also read from the OTLP name severityNumber) and is derived from severityText when missing.
      Parameters:
      node - JSON object
      Returns:
      the record
      Throws:
      ValidationException - when the node is not a valid record
    • toAttrValue

      public static Object toAttrValue(com.fasterxml.jackson.databind.JsonNode node)
      Converts a JSON tree into attribute values (AttrValues).
      Parameters:
      node - JSON value
      Returns:
      String, Long, Double, Boolean, List or Map