stackdriver

package
v0.12.67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 3

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

View Source
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

func NewFormatter(w io.Writer, logName string, ops ...xlog.FormatterOption) xlog.Formatter

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.

func String

func String(value any) string

String returns JSON without HTML escaping. Errors without json.Marshaler support use their detailed text. Encoding failures are ignored and return an empty string. This helper is separate from the formatter's KV encoding.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL