log

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package log provides the slog handler that automatically tags every log record with the correlation_id from context.

Wiring: main.go wraps slog.NewJSONHandler in CorrelationHandler and installs it as the default logger. After that, every slog.InfoContext(ctx, ...) call carries the correlation_id without the caller having to add it manually.

Spec: specs/system/correlation.spec.yaml AC-12, AC-13.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CorrelationHandler

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

CorrelationHandler wraps another slog.Handler. On every record, it inspects the supplied context for a correlation ID and, when present, adds it as a top-level attribute on the record before delegating.

When the context carries no ID (e.g., a slog.Info call without ctx, or a ctx that never went through the HTTP middleware), the wrapper does nothing — the record is emitted without correlation_id. The forbidigo lint rule (active from Day 4) flags non-Context slog calls so this situation is rare and intentional (boot-time only).

func NewCorrelationHandler

func NewCorrelationHandler(inner slog.Handler) *CorrelationHandler

NewCorrelationHandler wraps the inner handler. The inner handler does the actual writing; this wrapper just tags records.

func (*CorrelationHandler) Enabled

func (h *CorrelationHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled delegates to the inner handler.

func (*CorrelationHandler) Handle

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

Handle adds correlation_id (when present) and delegates.

func (*CorrelationHandler) WithAttrs

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

WithAttrs preserves the chain. The wrapper itself doesn't hold state; the inner handler's WithAttrs is honored.

func (*CorrelationHandler) WithGroup

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

WithGroup preserves the chain.

Jump to

Keyboard shortcuts

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