Skip to content

feat(logger): Wrapper to extract and log context#4863

Merged
Ly-Joey merged 4 commits into
google:masterfrom
Ly-Joey:log-context-wrapper
Feb 23, 2026
Merged

feat(logger): Wrapper to extract and log context#4863
Ly-Joey merged 4 commits into
google:masterfrom
Ly-Joey:log-context-wrapper

Conversation

@Ly-Joey

@Ly-Joey Ly-Joey commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Add a contextHandler to wrap around our slog.Handler so that key-value stored in context will be automatically added to the log as attributes.

Services will have to explicitly register what context keys they want to show up in logs.
To register a context key to be logged (after initializing the logger):

logger.RegisterContextKey(ctxKey, logKey)

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

another-rex
another-rex previously approved these changes Feb 22, 2026

@another-rex another-rex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very nice!

Comment thread go/cmd/gitter/gitter.go Outdated
@Ly-Joey Ly-Joey force-pushed the log-context-wrapper branch from 39d08ed to 6d79815 Compare February 23, 2026 01:01
@Ly-Joey Ly-Joey requested a review from another-rex February 23, 2026 02:05
@Ly-Joey Ly-Joey merged commit b859ff4 into google:master Feb 23, 2026
19 checks passed
@Ly-Joey Ly-Joey deleted the log-context-wrapper branch February 25, 2026 01:08
tymzd pushed a commit to tymzd/osv.dev that referenced this pull request Apr 13, 2026
Add a contextHandler to wrap around our slog.Handler so that key-value
stored in context will be automatically added to the log as attributes.

Services will have to explicitly register what context keys they want to
show up in logs.
To register a context key to be logged (after initializing the logger):
```
logger.RegisterContextKey(ctxKey, logKey)
```
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.

2 participants