Documentation
¶
Overview ¶
Package logx builds a configured log/slog logger (level and text/json format, with optional console and file outputs).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLogger ¶
NewLogger constructs a *slog.Logger from LogConfig. Console output is always enabled unless config.Console.Enabled=false. A second file output is added when config.File.Enabled=true and config.File.Path is set. Each output has its own level and format, falling back to config.Level and config.Format.
func WithMinLevel ¶ added in v0.33.0
WithMinLevel returns a logger that additionally drops records below level, on top of whatever the underlying handler already filters. An empty or unrecognized level returns logger unchanged. Use it to raise the floor for a noisy component — e.g. HTTP access logs or gRPC request logs — independently of the global level, so the app can run at debug while a component logs only warnings and errors. Valid levels: debug, info, warn, error.
Types ¶
type LogConfig ¶
type LogConfig struct {
Level string `mapstructure:"level"`
Format string `mapstructure:"format"`
Console *LogOutputConfig `mapstructure:"console"`
File *LogOutputConfig `mapstructure:"file"`
}
LogConfig configures the logger. Console output is always enabled unless explicitly disabled via Console.Enabled=false. A file output is added when File.Enabled=true and File.Path is set. Each output can independently override the top-level Level and Format. Valid levels: debug, info, warn, error. Valid formats: text, json.
type LogOutputConfig ¶
type LogOutputConfig struct {
Enabled bool `mapstructure:"enabled"`
Level string `mapstructure:"level"` // overrides LogConfig.Level for this output
Format string `mapstructure:"format"` // overrides LogConfig.Format for this output
Path string `mapstructure:"path"` // file output only; parent dirs are created automatically
}
LogOutputConfig configures a single log output destination (console or file).