Documentation
¶
Index ¶
Constants ¶
const ( // Level types LevelDebug = "debug" LevelInfo = "info" LevelWarn = "warn" LevelError = "error" // Format types FormatJSON = "json" FormatText = "text" FormatRaw = "raw" FormatPretty = "pretty" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ContextHandler ¶
type ContextHandler struct {
// contains filtered or unexported fields
}
ContextHandler wraps an slog.Handler and extracts values from context before logging.
func NewContextHandler ¶
func NewContextHandler(handler slog.Handler, extract ExtractFromContextFn) *ContextHandler
NewContextHandler creates a new handler that extracts context values before delegating to the wrapped handler.
type ExtractFromContextFn ¶
ExtractFromContextFn defines a function that extracts key-value pairs from context. It should return pairs of keys and values as []any, e.g., []any{"key1", "value1", "key2", "value2"}
type Opts ¶
type Opts struct {
Fields []string `long:"field" env:"FIELD" description:"Inject fields at the topline level, using k:v"`
Level string `long:"level" env:"LEVEL" description:"Log level: debug, info, warn, error" default:"info"`
Format string `long:"format" env:"FORMAT" description:"Log format: json, text, raw, pretty" default:"json"`
FilePath string `long:"file" env:"FILE" description:"Log to file instead of stderr"`
}
Opts holds logging configuration options.
type RawHandler ¶
type RawHandler struct {
// contains filtered or unexported fields
}
RawHandler is a simple handler that outputs messages with key-value pairs in a simple format.
func NewRawHandler ¶
func NewRawHandler(w io.Writer, opts *slog.HandlerOptions) *RawHandler
NewRawHandler creates a new RawHandler.
func (*RawHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level.