Skip to content

Add the context-aware log level - #12

Merged
a-menshchikov merged 1 commit into
mainfrom
slogger
Nov 11, 2026
Merged

a-menshchikov merged 1 commit into
mainfrom
slogger

Conversation

@a-menshchikov

Copy link
Copy Markdown
Member

WithLevel puts a log level into the context, and the handler of the logger reads it back: the level of the context takes precedence over the level of the logger, so a single request can be logged at its own level.

The check is made in the Enabled method of the handler, before the record is formatted. The level of the context is only seen by the *Context methods of the logger, the ones that take a context.

The logger built by New and NewToContext wraps its handler, so the level of the context is applied out of the box. NewLevelHandler is exported for the loggers that are built by the user.

WithLevel puts a log level into the context, and the handler of the logger
reads it back: the level of the context takes precedence over the level of
the logger, so a single request can be logged at its own level.

The check is made in the Enabled method of the handler, before the record is
formatted. The level of the context is only seen by the *Context methods of
the logger, the ones that take a context.

The logger built by New and NewToContext wraps its handler, so the level of
the context is applied out of the box. NewLevelHandler is exported for the
loggers that are built by the user.
@a-menshchikov
a-menshchikov merged commit 4890aba into main Nov 11, 2026
25 checks passed
@a-menshchikov
a-menshchikov deleted the slogger branch November 11, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant