-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Create way to add key-value pairs to new sinks #4582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Nevermind! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
mcastorina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Feels kind of kludgey but it works.
| // New key-value pairs cannot be ergonomically added directly to cores. logr has code to do it, but that code is not | ||
| // exported. Rather than replicating it ourselves, we indirectly use it by creating a temporary logger for the new | ||
| // core, adding the key-value pairs to the temporary logger, and then extracting the temporary logger's modified | ||
| // core. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "non-ergonomic way" you're referring to the Core.With method?
Description:
Counterintuitively, a new sink added to an existing logger will not inherit the existing logger's key-value pairs. This has only caused a problem in practice with respect to a small number of known key-value pairs, so this PR creates a way to add specific key-value pairs to new sinks.
This will supersede #4579.
Checklist:
make test-community)?make lintthis requires golangci-lint)?