Documentation
¶
Overview ¶
Package slogutil provides configuration and setup utilities for slog.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidFormat = errors.New("invalid log format")
ErrInvalidFormat is returned when Format contains an unrecognized value.
var ErrInvalidLevel = errors.New("invalid log level")
ErrInvalidLevel is returned when Level contains an unrecognized value.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Level is the minimum log level.
// Valid values: "debug", "info", "warn", "warning", "error".
// Default: "info"
Level string `koanf:"level"`
// Format is the output format.
// Valid values: "text", "json".
// Default: "text"
Format string `koanf:"format"`
}
Config holds configuration for slog setup.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type ContextHandler ¶ added in v0.8.0
type ContextHandler struct {
// contains filtered or unexported fields
}
ContextHandler is a slog.Handler that adds request_id, tenant_id, user_id, correlation_id, trace_id and span_id from the record's context before passing the record to the wrapped handler. Fields whose value is empty or missing are omitted. trace_id and span_id come from the active OpenTelemetry span context.
Fields are added to the record, so they are nested under any group opened with WithGroup.
func NewContextHandler ¶ added in v0.8.0
func NewContextHandler(next slog.Handler) *ContextHandler
NewContextHandler returns a ContextHandler that wraps next.
func (*ContextHandler) Enabled ¶ added in v0.8.0
Enabled reports whether the wrapped handler handles records at level.
func (*ContextHandler) Handle ¶ added in v0.8.0
Handle adds the context fields to r and passes it to the wrapped handler.