pkgsitegolang.org/x/pkgsite/internal/log/stackdriverlogger Index | Files

package stackdriverlogger

import "golang.org/x/pkgsite/internal/log/stackdriverlogger"

Package log supports structured and unstructured logging with levels to GCP stackdriver.

Index

Functions

func New

func New(ctx context.Context, logName, projectID string, opts []logging.LoggerOption) (_ log.Logger, _ *logging.Logger, err error)

New creates a new Logger that logs to Stackdriver. It assumes config.Init has been called. New returns a "parent" *logging.Logger that should be used to log the start and end of a request. It also creates and remembers internally a "child" log.Logger that will be used to log within a request. The child logger should be passed to log.Use to forward the log package's logging calls to the child logger. The two loggers are necessary to get request-scoped logs in Stackdriver. See https://cloud.google.com/appengine/docs/standard/go/writing-application-logs.

New can only be called once. If it is called a second time, it returns an error.

func NewContextWithLabel

func NewContextWithLabel(ctx context.Context, key, value string) context.Context

NewContextWithLabel creates a new context from ctx that adds a label that will appear in the log entry.

Source Files

log.go

Version
v0.0.0-20250218150137-224a1368cf02 (latest)
Published
Feb 18, 2025
Platform
linux/amd64
Imports
12 packages
Last checked
2 months ago

Tools for package owners.