Skip to main content

Module format

Module format 

Source
Expand description

The text and JSON log formats.

The JSON format writes one object per line, with these keys, in this order:

  • timestamp: RFC 3339 UTC time, with microseconds
  • level: TRACE, DEBUG, INFO, WARN, or ERROR
  • severity: the same level as a Google Cloud Logging severity
  • message
  • target: the module that logged the event
  • the event’s fields
  • spans: the spans the event happened in, outermost first, if any
  • code.file.path and code.line.number, if known
  • trace_id and span_id, if the event is in a sampled OpenTelemetry trace

An event field whose name is one of these keys is written as field.<name>.

StructsΒ§

JsonEscaper πŸ”’
Escapes text for the inside of a JSON string, and stops once the escaped text reaches a byte limit.
JsonVisitor πŸ”’
Writes fields as "name":value pairs, separated by commas.
MessageVisitor πŸ”’
Writes an event’s message field as a JSON string, or "" if it has none.

EnumsΒ§

EventFormat
Formats events in the configured LogFormat.
FieldFormat
Formats span fields to match the EventFormat.
Fields πŸ”’
Which fields a JsonVisitor is writing.

ConstantsΒ§

MAX_EXACT_INTEGER πŸ”’
Integers further from zero than this are written as strings, because many JSON parsers, including Google Cloud Logging’s, read numbers as 64-bit floats.
MAX_LINE_LEN πŸ”’
The longest line written, in bytes.
MAX_VALUE_LEN πŸ”’
The longest field value written, in bytes after JSON escaping. Longer values are truncated.
RESERVED_KEYS πŸ”’
The keys of every line. Event fields with these names are renamed.
TRUNCATED πŸ”’
Marks a truncated value.

FunctionsΒ§

escape_json πŸ”’
Writes text with JSON string escapes, and subtracts the bytes that escapes add from remaining.
is_global_span πŸ”’
Returns true for the span Zebra enters for the life of the process.
json_panic_line πŸ”’
Returns a panic as one JSON log line, without a line break.
severity
Returns the Google Cloud Logging severity for level.
write_fixed_keys πŸ”’
Writes the opening brace, timestamp, level, and severity.
write_json_debug πŸ”’
Writes value’s Debug output as a JSON string, truncated to MAX_VALUE_LEN.
write_json_display πŸ”’
Writes value’s Display output as a JSON string, truncated to MAX_VALUE_LEN.
write_json_line πŸ”’
Writes event as a JSON object, without a line break.
write_json_str πŸ”’
Writes value as a JSON string, truncated to MAX_VALUE_LEN.
write_spans πŸ”’
Writes the event’s spans from the root, as "spans":[...], unless it has none apart from the global span.
write_trace_ids πŸ”’
Writes the IDs of the exported span closest to the event, if that span is sampled.
write_truncated_json_line πŸ”’
Writes an event that is too long for one line, keeping its fixed keys and the start of its message.