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.