-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Replace --debug
and --trace
with a fine-grained --log-level
flag
#3703
Conversation
if l == -1 { | ||
// Zap uses "5" as the value for fatal. | ||
// We need to pass in "-5" because `SetLevel` passes the negation. | ||
log.SetLevel(-5) |
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.
This technically works because there's no logs with this level. Perhaps there's a better way to disable logging.
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.
Yeah, this is unfortunate if it's the best we can do. If it is, I think it's worth leaving an apologetic, explanatory 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.
This works, but another idea is to use logr.Discard.
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.
I'm not familiar enough with the logging setup. How would you implement logr.Discard
?
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.
I think this PR provides a cleaner interface to logging and is in a mergable state. I'm unfamiliar with logr.Discard
as well. We can always follow-up if it turns out this change needs more.
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.
This is neat, thanks for doing it! I would like to also get the opinions of @zricethezav and @mcastorina.
// Zap uses "5" as the value for fatal. | ||
// We need to pass in "-5" because `SetLevel` passes the negation. |
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.
I have some dumb questions:
- What does "uses 5 as the value for fatal" mean here? Are fatal errors are logged at level 5?
- Why does
SetLevel
pass the negation? That seems really strange.
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.
What does "uses 5 as the value for fatal" mean here? Are fatal errors are logged at level 5?
Zap's logging levels use 0
for info, with negatives increasing verbosity and 1-5 decreasing verbosity.
TruffleHog only seems to use levels <= 0, so setting the level to 5
effectively prevents anything from being logged.
Why does SetLevel pass the negation? That seems really strange.
My guess is that someone preferred the look of (+)1->5 for verbosity and not (-)1->5. 🤷♂️
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.
It originates from the combination of zap
as the log implementation for logr
.
logr
defines higher numbers as being more verbosezap
defines lower numbers as being more verbose
I left a comment about it in SetLevel
:
Lines 27 to 29 in 2a01091
// Zap's levels get more verbose as the number gets smaller, as explained | |
// by zapr here: https://github.com/go-logr/zapr#increasing-verbosity | |
// For example setting the level to -2 below, means log.V(2) will be enabled. |
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.
Ah, I didn't realize it was two different implementations.
if l == -1 { | ||
// Zap uses "5" as the value for fatal. | ||
// We need to pass in "-5" because `SetLevel` passes the negation. | ||
log.SetLevel(-5) |
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.
Yeah, this is unfortunate if it's the best we can do. If it is, I think it's worth leaving an apologetic, explanatory comment.
Description:
This was motivated by the discussion in #3589.
It fixes #3668.
Checklist:
make test-community
)?make lint
this requires golangci-lint)?