MCPcopy
hub / github.com/uber-go/zap / convertSlogLevel

Function convertSlogLevel

exp/zapslog/handler.go:119–130  ·  view source on GitHub ↗

convertSlogLevel maps slog Levels to zap Levels. Note that there is some room between slog levels while zap levels are continuous, so we can't 1:1 map them. See also https://go.googlesource.com/proposal/+/master/design/56345-structured-logging.md?pli=1#levels

(l slog.Level)

Source from the content-addressed store, hash-verified

117// Note that there is some room between slog levels while zap levels are continuous, so we can't 1:1 map them.
118// See also https://go.googlesource.com/proposal/+/master/design/56345-structured-logging.md?pli=1#levels
119func convertSlogLevel(l slog.Level) zapcore.Level {
120 switch {
121 case l >= slog.LevelError:
122 return zapcore.ErrorLevel
123 case l >= slog.LevelWarn:
124 return zapcore.WarnLevel
125 case l >= slog.LevelInfo:
126 return zapcore.InfoLevel
127 default:
128 return zapcore.DebugLevel
129 }
130}
131
132// Enabled reports whether the handler handles records at the given level.
133func (h *Handler) Enabled(ctx context.Context, level slog.Level) bool {

Callers 2

EnabledMethod · 0.85
HandleMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected