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 microsecondslevel:TRACE,DEBUG,INFO,WARN, orERRORseverity: the same level as a Google Cloud Logging severitymessagetarget: the module that logged the event- the eventβs fields
spans: the spans the event happened in, outermost first, if anycode.file.pathandcode.line.number, if knowntrace_idandspan_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Β§
- Json
Escaper π - Escapes text for the inside of a JSON string, and stops once the escaped text reaches a byte limit.
- Json
Visitor π - Writes fields as
"name":valuepairs, separated by commas. - Message
Visitor π - Writes an eventβs
messagefield as a JSON string, or""if it has none.
EnumsΒ§
- Event
Format - Formats events in the configured
LogFormat. - Field
Format - Formats span fields to match the
EventFormat. - Fields π
- Which fields a
JsonVisitoris 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
textwith JSON string escapes, and subtracts the bytes that escapes add fromremaining. - is_
global_ πspan - Returns
truefor 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, andseverity. - write_
json_ πdebug - Writes
valueβsDebugoutput as a JSON string, truncated toMAX_VALUE_LEN. - write_
json_ πdisplay - Writes
valueβsDisplayoutput as a JSON string, truncated toMAX_VALUE_LEN. - write_
json_ πline - Writes
eventas a JSON object, without a line break. - write_
json_ πstr - Writes
valueas a JSON string, truncated toMAX_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.