Documentation
¶
Index ¶
- func NewSlogLogger() log.Logger
- type LevelFilter
- func (f LevelFilter) Debug(ctx context.Context, msg string, args ...any)
- func (f LevelFilter) Enabled(level log.Level) bool
- func (f LevelFilter) Error(ctx context.Context, msg string, args ...any)
- func (f LevelFilter) Info(ctx context.Context, msg string, args ...any)
- func (f LevelFilter) Warn(ctx context.Context, msg string, args ...any)
- func (f LevelFilter) With(args ...any) log.Logger
- type MultiLogger
- func (m MultiLogger) Debug(ctx context.Context, msg string, args ...any)
- func (m MultiLogger) Enabled(level log.Level) bool
- func (m MultiLogger) Error(ctx context.Context, msg string, args ...any)
- func (m MultiLogger) Info(ctx context.Context, msg string, args ...any)
- func (m MultiLogger) Warn(ctx context.Context, msg string, args ...any)
- func (m MultiLogger) With(args ...any) log.Logger
- type SlogLogger
- func (s SlogLogger) Debug(ctx context.Context, msg string, args ...any)
- func (s SlogLogger) Enabled(level log.Level) bool
- func (s SlogLogger) Error(ctx context.Context, msg string, args ...any)
- func (s SlogLogger) Info(ctx context.Context, msg string, args ...any)
- func (s SlogLogger) Warn(ctx context.Context, msg string, args ...any)
- func (s SlogLogger) With(args ...any) log.Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSlogLogger ¶
NewSlogLogger builds a SlogLogger backed by the stdlib slog with sensible defaults: a text handler writing to stderr at INFO level.
Callers needing a different format / level / destination should either:
- build their own *slog.Logger and wrap it: SlogLogger{L: myLogger}
- or implement the [Logger] interface themselves and pass it to [SetLogger].
Types ¶
type LevelFilter ¶
type LevelFilter struct {
// Logger is the underlying logger that receives forwarded messages.
Logger log.Logger
// Level is the minimum severity; messages below this level are discarded.
Level log.Level
}
LevelFilter wraps a [Logger] and discards messages whose level is below the configured LevelFilter.Level. This allows callers to control verbosity at the call site while keeping the underlying logger unchanged — a natural fit for the composable (Lego-like) design philosophy of go-wind.
Usage:
l := log.LevelFilter{Logger: log.NewSlogLogger(), Level: log.LevelWarn}
l.Debug(ctx, "hidden") // discarded
l.Error(ctx, "visible") // forwarded
func (LevelFilter) Debug ¶
func (f LevelFilter) Debug(ctx context.Context, msg string, args ...any)
Debug forwards to the underlying logger only when the filter threshold permits DEBUG level.
func (LevelFilter) Enabled ¶
func (f LevelFilter) Enabled(level log.Level) bool
Enabled reports whether the underlying logger would emit at the given level AND that level is at or above the filter threshold.
func (LevelFilter) Error ¶
func (f LevelFilter) Error(ctx context.Context, msg string, args ...any)
Error forwards to the underlying logger only when the filter threshold permits ERROR level.
func (LevelFilter) Info ¶
func (f LevelFilter) Info(ctx context.Context, msg string, args ...any)
Info forwards to the underlying logger only when the filter threshold permits INFO level.
type MultiLogger ¶
type MultiLogger struct {
// Loggers is the slice of loggers that receive fanned-out records.
Loggers []log.Logger
}
MultiLogger fans out log records to multiple [Logger] instances in order. If any logger panics, the remaining loggers still receive the record via a deferred recover.
This is useful when you need to send logs to both stderr (for local debugging) and a remote collection service simultaneously:
ml := log.MultiLogger{Loggers: []log.Logger{
log.NewSlogLogger(),
myRemoteLogger,
}}
log.SetLogger(ml)
type SlogLogger ¶
type SlogLogger struct {
// L is the underlying slog logger. It MUST be non-nil; [NewSlogLogger]
// always returns a ready-to-use instance.
L *slog.Logger
}
SlogLogger adapts the stdlib *slog.Logger to the [Logger] interface.
This is the reference implementation returned by NewSlogLogger. Callers that already own a configured *slog.Logger can wrap it directly:
log.SetLogger(log.SlogLogger{L: mySlogLogger})
func (SlogLogger) Debug ¶
func (s SlogLogger) Debug(ctx context.Context, msg string, args ...any)
Debug forwards to slog.Logger.DebugContext.
func (SlogLogger) Enabled ¶
func (s SlogLogger) Enabled(level log.Level) bool
Enabled maps the wind [Level] to the equivalent slog level and reports whether the underlying *slog.Logger would emit a record at that level.
func (SlogLogger) Error ¶
func (s SlogLogger) Error(ctx context.Context, msg string, args ...any)
Error forwards to slog.Logger.ErrorContext.
func (SlogLogger) Info ¶
func (s SlogLogger) Info(ctx context.Context, msg string, args ...any)
Info forwards to slog.Logger.InfoContext.
func (SlogLogger) Warn ¶
func (s SlogLogger) Warn(ctx context.Context, msg string, args ...any)
Warn forwards to slog.Logger.WarnContext.
func (SlogLogger) With ¶
func (s SlogLogger) With(args ...any) log.Logger
With returns a new SlogLogger whose underlying *slog.Logger has the given key-value pairs attached. This is typically used to distinguish modules, e.g., logger.With("module", "registry"). The returned logger will include these attributes in every log record it produces.