Levels
Options.Level is the lowest level the handler logs. It is a slog.Leveler, so it can be a fixed slog.Level
or a *slog.LevelVar that changes. Left nil, it is slog.LevelInfo, as for slog’s own handlers.
h := golog.NewHandler(os.Stderr, &golog.Options{Level: slog.LevelDebug})A record below the level is dropped by the logger before any of its values are formatted. Dropping a Debug record with five attributes costs a few nanoseconds and allocates nothing.
Changing the level while running
Section titled “Changing the level while running”Pass a *slog.LevelVar and set it whenever you like, from any goroutine. The handler reads it on every record,
and so do the handlers derived from it with With and WithGroup:
var level slog.LevelVar // Info until it is setlogger := slog.New(golog.NewHandler(os.Stderr, &golog.Options{Level: &level}))
// Later, from any goroutine, while others log:level.Set(slog.LevelDebug)The levels
Section titled “The levels”| Level | Value | Written as |
|---|---|---|
slog.LevelDebug |
-4 | DEBUG |
slog.LevelInfo |
0 | INFO |
slog.LevelWarn |
4 | WARN |
slog.LevelError |
8 | ERROR |
golog.LevelCritical |
12 | CRITICAL |
A level between two of these is written as the one below it and the difference, as slog does: INFO+2, ERROR+1.
Critical
Section titled “Critical”golog.LevelCritical is v1’s Critical: a failure that needs someone now, above an error. Log at it with Log:
logger.Log(ctx, golog.LevelCritical, "disk full", "path", "/var/lib/db")2026-10-24T09:41:07.312+11:00 CRITICAL disk full path=/var/lib/dbslog’s own handlers write it as ERROR+4. If the same records also go to one of them, ReplaceAttr can name it:
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { if a.Key == slog.LevelKey && groups == nil && a.Value.Any() == golog.LevelCritical { return slog.String(a.Key, "CRITICAL") } return a},Coming from v1’s verbosity bits
Section titled “Coming from v1’s verbosity bits”v1’s verbosity was a set of levels, such as golog.Warning | golog.Error. slog’s is a minimum: everything at the
level and above is logged. Most sets were “this level and up”, which is the level itself:
| v1 | v2 |
|---|---|
golog.DefaultVerbosity, every level |
slog.LevelDebug |
golog.Info | golog.Warning | golog.Error | golog.Critical |
slog.LevelInfo |
golog.Warning | golog.Error | golog.Critical |
slog.LevelWarn |
golog.Error | golog.Critical |
slog.LevelError |
golog.Critical |
golog.LevelCritical |
golog.Disabled |
slog.DiscardHandler in place of the handler |
A set with a gap in it, such as Debug alone, needs a handler of your own around golog’s that decides in Enabled.