-
Notifications
You must be signed in to change notification settings - Fork 574
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
Add EmptyFields method to remove all the fileds from logger #575
Conversation
@rs sorry to bother you, but can you give me your brief opinion on the idea? Like, do you think it's a nice feature and will review it one day in the future, or do you have doubts about whether it's needed or not and I should probably just use a fork of mine? |
What about renaming this method |
Upvote from me, I have a use for this. I might suggest |
Co-authored-by: Olivier Poitrey <[email protected]>
Co-authored-by: Olivier Poitrey <[email protected]>
Co-authored-by: Olivier Poitrey <[email protected]>
Co-authored-by: Olivier Poitrey <[email protected]>
Thank you very much for the thorough review @rs ! P.S.: it's very nice of you to highlight all the places where the function should be renamed, it just took me a few clicks. |
Co-authored-by: tlipoca9 <[email protected]>
Hello dear zerolog maintainers! First of all, thanks for the great logging package, which is also the fastest logger available. Hats off to everyone who worked on it.
This feature adds the ability to clear all previously added fields when creating a new logger.
Sometimes, when I pass the logger from one part of my service to another, I want to keep all the logger settings, but remove all the fields. For example, I can use the same field name to identify the context of the logger. If I reuse it, the result will have many fields with the same name, which doesn't look good:
{"level":"info","context":"internal-logic","context":"db-adapter","context":"db-driver","message":"something"}
Using this method, I can create a new logger instance like this:
log.With().EmptyFields().Str("context","db-driver").Logger()
And later have messages with only one "context" field:
{"level":"info","context":"db-driver","message":"something"}