Documentation
¶
Overview ¶
Package stackdriver provides xlog's Google Cloud Logging (formerly Stackdriver) formatter. It writes local JSON records; it does not upload logs or provide a Cloud Logging client.
Example:
formatter := stackdriver.NewFormatter(os.Stdout, "app")
xlog.SetFormatter(formatter)
logger := xlog.NewPackageLogger("example.com/app", "main")
logger.KV(xlog.INFO, "attempt", 1)
Output fields include logName, component, timestamp, severity, message (an object), and sourceLocation. TRACE and DEBUG both map to DEBUG. Configure options before logging. Values use JSON encoding: strings retain their type, integers remain JSON numbers, durations and display enums become strings, and custom JSON marshalers control their representation. The formatter also implements xlog.ErrorFormatter to report encoding and destination failures.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MaxLogMessageLength = 2 * 1024
MaxLogMessageLength limits plain messages in bytes before appending "...". It does not limit KV fields. Configure it before logging; negative values panic when formatting a message. This is independent of xlog.FormatMaxLogLength.
Functions ¶
func NewFormatter ¶
NewFormatter returns a Stackdriver formatter for xlog, writing log entries as Stackdriver-compatible JSON. logName sets the Stackdriver log name. Options apply before the destination is bound, so xlog.WithSink takes effect immediately and delivers rendered records on the sink worker.
Types ¶
This section is empty.