logger

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logger provides structured logging utilities.

Index

Constants

View Source
const (
	LevelDebugExtra = slog.Level(-8)
	LevelExtreme    = slog.Level(-12)
)

Variables

This section is empty.

Functions

func DebugExtraContext

func DebugExtraContext(ctx context.Context, msg string, args ...any)

func ExtremeContext

func ExtremeContext(ctx context.Context, msg string, args ...any)

func GCPReplaceAttr

func GCPReplaceAttr(groups []string, a slog.Attr) slog.Attr

GCPReplaceAttr replaces slog attributes with attributes GCP understands.

Types

type Enricher

type Enricher struct {
	// contains filtered or unexported fields
}

Enricher injects GCP metadata in the record attributes.

func NewEnricher

func NewEnricher(delegate slog.Handler, projectID string) *Enricher

NewEnricher wraps the provided slog.Handler. It injects GCP Cloud Logging compatible trace fields extracted from the context if a valid span is present.

func (*Enricher) Enabled

func (h *Enricher) Enabled(ctx context.Context, l slog.Level) bool

Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.

func (*Enricher) Handle

func (h *Enricher) Handle(ctx context.Context, r slog.Record) error

Handle adds the trace ID, span ID, and sampled flag to the record attributes.

func (*Enricher) WithAttrs

func (h *Enricher) WithAttrs(as []slog.Attr) slog.Handler

WithAttrs returns a new handler with the given attributes, preserving the GCP handling.

func (*Enricher) WithGroup

func (h *Enricher) WithGroup(g string) slog.Handler

WithGroup returns a new handler with the given group name, preserving the GCP handling.

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter logs record to GCP Cloud Logging API.

func NewExporter

func NewExporter(logger *logging.Logger, level slog.Level) *Exporter

NewExporter creates an slog.Handler that directly logs to GCP Cloud logging.

func (*Exporter) Enabled

func (h *Exporter) Enabled(_ context.Context, lvl slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*Exporter) Handle

func (h *Exporter) Handle(ctx context.Context, r slog.Record) error

Handle converts a record to a Cloud Logging entry, and logs it.

func (*Exporter) WithAttrs

func (h *Exporter) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements Handler.WithAttrs.

func (*Exporter) WithGroup

func (h *Exporter) WithGroup(name string) slog.Handler

WithGroup implements Handler.WithGroup.

type MultiHandler

type MultiHandler struct {
	// contains filtered or unexported fields
}

MultiHandler is a Exporter that invokes all the given Handlers. Its Enabled method reports whether any of the handlers' Enabled methods return true. Its Handle, WithAttrs and WithGroup methods call the corresponding method on each of the enabled handlers. Copied from slog. TODO: Move to slog.MultiHandler once the project has moved to go 1.26

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) *MultiHandler

NewMultiHandler creates a MultiHandler with the given Handlers.

func (*MultiHandler) Enabled

func (h *MultiHandler) Enabled(ctx context.Context, l slog.Level) bool

func (*MultiHandler) Handle

func (h *MultiHandler) Handle(ctx context.Context, r slog.Record) error

func (*MultiHandler) WithAttrs

func (h *MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*MultiHandler) WithGroup

func (h *MultiHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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