Skip to content

Pass FromContext(...) context to slog handler#425

Open
inteon wants to merge 2 commits intogo-logr:masterfrom
inteon:slog_context
Open

Pass FromContext(...) context to slog handler#425
inteon wants to merge 2 commits intogo-logr:masterfrom
inteon:slog_context

Conversation

@inteon
Copy link

@inteon inteon commented Mar 9, 2026

Instead of passing context.Background(), we now pass the context passed to FromContext(...) to the slog .Handle(...) function instead.

This is an alternative solution to the problem presented in #158 (only solves the use case where an slog backend is used).

cc @pohly

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
Copy link
Contributor

@pohly pohly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this only solves #158 for logging with a slog backend.

…thContext

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@inteon inteon requested a review from pohly March 9, 2026 13:55
// slog.LevelInfo and V(4) becomes slog.LevelDebug.
//
// The provided context is passed to the slog.Handler when logging. This allows
// the slog.Handler to use the context. This should only be used for short-lived
Copy link

@obarisk obarisk Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the following a little more descriptive?

an slog which following the lifecycle of the context

not limit to the vague long lived v.s. short lived

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide a diff? I would like to understand exactly what you would like to change, as I think that the current comment is quite clear already.

@obarisk
Copy link

obarisk commented Mar 11, 2026

following the context of #158
when we need specific context related event, e.g. trace context

context of logger is not really helpful if we are going to take the information in context for log events

with current implementation, we have to create logger for those events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants