Documentation
¶
Index ¶
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, fields ...zap.Field)
- func Info(msg string, fields ...zap.Field)
- func Init(cfg Config) error
- func LevelHandler() http.Handler
- func SetLevel(level zapcore.Level)
- func Warn(msg string, fields ...zap.Field)
- type Config
- type Logger
- type SamplingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LevelHandler ¶
LevelHandler returns an http.Handler that serves the current log level and accepts PUT requests with JSON body {"level":"debug"} to change it at runtime. Mount at an internal route, e.g.: router.PUT("/internal/log/level", gin.WrapH(logger.LevelHandler()))
Types ¶
type Config ¶
type Config struct {
// Level is the minimum log level: "debug", "info", "warn", "error". Default: "info".
Level string
// Format is the output format: "json" or "console". Default: "json".
Format string
// Sampling enables log sampling when non-nil.
Sampling *SamplingConfig
// StacktraceLevel is the level at which stack traces are attached. Default: "error".
StacktraceLevel string
}
Config controls logger initialization.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a thin wrapper around zap.Logger. A Logger created via With() stores fields for deferred resolution so that package-level vars like `var log = logger.With(...)` pick up the real logger even when evaluated before Init().
func With ¶
With returns a deferred child Logger with pre-attached fields (e.g. component name). Safe to call before Init() — the real logger is resolved at log time.
type SamplingConfig ¶
type SamplingConfig struct {
// Tick is the sampling window. Default: 1s.
Tick time.Duration
// Initial is the number of log entries emitted in full per Tick.
Initial int
// Thereafter emits one entry per this many after Initial is exhausted.
Thereafter int
}
SamplingConfig controls high-frequency log noise reduction.