Skip to content
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

WithValues with the same key repeats the field #170

Closed
gshirazi opened this issue Jan 20, 2023 · 4 comments
Closed

WithValues with the same key repeats the field #170

gshirazi opened this issue Jan 20, 2023 · 4 comments
Assignees

Comments

@gshirazi
Copy link

log = log.WithValues("k", "v1")
log = log.WithValues("k", "v2")

I would expect that resulting log contain only {"k": "v2"} but it contains both {"k": "v1" , "k": "v2"}. How to de-duplicate?

@pohly
Copy link
Contributor

pohly commented Jan 20, 2023

This needs to be implemented by the logger implementation. Which one are you using?

@gshirazi
Copy link
Author

zapr

@pohly
Copy link
Contributor

pohly commented Jan 20, 2023

zapr just hands over to the upstream zap logger: https://github.com/go-logr/zapr/blob/48df242fffb25049c72e208aea4826177ff5fe8e/zapr.go#L222

I don't think we should override how zap handles this, so if you absolutely need this fixed, you should file an upstream issue: https://github.com/uber-go/zap/issues

However, it might be intentional. Finding duplicates has a performance impact, and it's mostly cosmetic because a JSON parser will only consider the most recent value, so {"k": "v1" , "k": "v2"} and { "k": "v2"} are equivalent.

@gshirazi
Copy link
Author

Got it, thanks a lot for explaination.

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

No branches or pull requests

3 participants