

set log level for global zap logger · Issue #870 · uber-go/zap · GitHub
source link: https://github.com/uber-go/zap/issues/870
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

New issue
set log level for global zap logger #870
Closed
celesteking opened this issue on Oct 23, 2020 · 3 comments
Closed
set log level for global zap logger #870
celesteking opened this issue on Oct 23, 2020 · 3 comments
Comments
I'm trying to set a log level for 3rd party lib that's using this package.
Go search in Google "zap logger set level" and you'll see the number of people that are struggling to do that. Why should it be so complicated? Couldn't you just come up with a simple and proper method to do that?
The app is doing this in init(): logger = zap.L().Named("dat:sqlx")
Is there a way to override that global level?
Thanks.
You'll need to create a new logger with the appropriate level, and use ReplaceGlobals
.
https://godoc.org/go.uber.org/zap#L
L returns the global Logger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.
zap doesn't have a SetLogger
method, because a child logger passed to some library should not have the ability to change the log level for all other loggers. The design separates the level from the logger, hence why there is no SetLevel
function, and we don't expect to add one.
This should really be documented in sane human manner. Just generating an APIdoc is the worst possible scenario after not having documentation at all.
Try searching on google, you'll see how many people are struggling.
Just noting that I'm using zerolog in my other projects, which has sane documentation and is easier to use, but sadly this one is uncontrollable from my part is it's a 3rd party lib that decided to use zap and sadly I have to find workarounds to make it log stuff.
@celesteking Please use a more respectful tone if you want your feedback to be heard.
Consider going over https://golang.org/conduct#values before engaging again.
Locking this thread for now.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
No one assigned
No milestone
Successfully merging a pull request may close this issue.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK