You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a fairly common pattern (attaching a logger to + reading a logger from a context). An example implementation of Enabled() with it could be:
// Enabled checks if the given level is enabled for the logger.func (*ZerologHandler) Enabled(ctx context.Context, level slog.Level) bool {
zl:=zerolog.Ctx(ctx)
switchlevel {
caseslog.LevelDebug:
returnzl.Debug().Enabled()
caseslog.LevelInfo:
returnzl.Info().Enabled()
caseslog.LevelWarn:
returnzl.Warn().Enabled()
caseslog.LevelError:
returnzl.Error().Enabled()
default:
returnfalse
}
}
(The above is not intended to cover fallbacks / overrides / alternative resolution methods, just a particular way to use zerolog.Ctx(ctx). Note also you could use zerolog.Ctx(ctx).GetLevel() if the above implementation is not adequate.)
The text was updated successfully, but these errors were encountered:
It's possible to attach a
zerolog
logger to a root contextand then later access it via
zerolog.Ctx(ctx)
.This is a fairly common pattern (attaching a logger to + reading a logger from a context). An example implementation of
Enabled()
with it could be:(The above is not intended to cover fallbacks / overrides / alternative resolution methods, just a particular way to use
zerolog.Ctx(ctx)
. Note also you could usezerolog.Ctx(ctx).GetLevel()
if the above implementation is not adequate.)The text was updated successfully, but these errors were encountered: