-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fixed Enabled() for lazy evaluation and supporting >2 V-level #25
Conversation
Support logr.Enabled() usage and undocumented zerologr.Level.
So you don't want to document how to make higher V levels work at all? This puts zerologr into the "not interesting" category, IMO. |
@thockin @pohly As I mentioned in the other thread, zapr is definitely much better choice than zerologr if higher than 2 verbosity (TraceLevel) is needed. Here are the reasons:
logr is greate for Go library users since any logging libraries (often the same one used in application code) can swap in without hardcoded. If users choose to use zerolog for application code, it is likely they know they can only use highest verbosity up to TraceLevel without reading zerolog's source code and can use all features like Sampling. On the other hand, if users prefer to using logr directly in application code, they have more freedom to choose from logr implementation. zerologr is the minimal glue between logr and zerolog and is limited by both. For example, logr does not support zerolog's WarnLevel/FatalLevel/PanicLevel. And zerolog does not support higher than logr.V(2) by default. Now, with this PR, it is possible for zerologr to support higher than logr.V(2) by setting EnforceLevelCheck=true but it breaks zerolog if zerolog's Hooks/Sampling is used. IMHO, it is better to keep zerologr less interesting and also less confusing by default. If users want to hack zerolog's undocumented level, there is an option to do so, but it is not offically supported. |
@thockin @pohly Also, maybe the root cause of this PR is where Enabled() should be called. I can move the dicussion to logr instead. About this line https://github.com/go-logr/logr/blob/master/logr.go#L274 Among all listed logr implementations, some (funcr, testr, glogr, klogr, ktesting, stdr, genericr, logfmtr) rely on logr.Enabled() check and the rest (zapr, zerologr, logrusr, gokitlogr, bufrlogr) check level again either in LogSink.Info() or underlying logging library calls. Since some established logging library already check level internally, it might be nice to move Enabled() call from Logr.Info() to LogSink.Info() to prevent the redundant Enabled() call in the logging hotpath, but that ship has sailed. |
The reason for it being in |
Understood the point of logr.Enabled() for lazy argument preparation. But it means that level checks will run two times for most logr implementation, three times for zerologr, may four times for zapr for single output. Don't have a better solution though. I will update PR to default to use redundant level check but give a fast path option for users who don't need it. |
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.
Thank you for taking additional verbosity into consideration, this implementation is much more graceful than mine. LGTM!
LGTM |
Close PR #22, #23, #24. Issue #20