-
Notifications
You must be signed in to change notification settings - Fork 5
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
Adds option to use non-global verbosity per logger. #26
Conversation
We alreayd have the global verbosity - what is the use-case for this? Can you show me what you are trying to solve or express? |
Let me know if you want to come back to this |
Hey, sorry about the slow follow-up—I missed the original notification. This introduces non-global verbosity, so I can have multiple instances of This means that if I can't reduce the volume of one package's logging vs. another if I use stdr. For example: // By default, we want to process all logs <= level 10
stdr.SetVerbosity(10)
normalService.logger = stdr.NewWithOptions(log.Default(), stdr.Options {})
// noisyService logs a lot of unimportant stuff at levels > 5, filter those out
// **Without this PR, it's not possible to do this.**
lvl := 5
noisyService.logger = stdr.NewWithOptions(log.Default(), stdr.Options {
Verbosity: &lvl,
}) I can already do this with testr, as follows: normalService.logger = testr.NewWithOptions(t, testr.Options {
Verbosity: 10
})
normalService.logger = testr.NewWithOptions(t, testr.Options {
Verbosity: 5
}) This PR brings the functionality of stdr in-line with what testr (and others) can do, without introducing a breaking API change (hence the use of the pointer) |
I see. I am not necessarily AGAINST this, but I think there's another way.
Does that work for you? |
ping again, ICYMI - I know I miss a lot of github emails :) |
I think it's similar, but not quite the same (unless I'm misunderstanding—very possible!) noisyService.logger = normalService.logger.V(5) ^ this has the effect of "everything that noisyService logs will become less important" lvl := 5
noisyService.logger = stdr.NewWithOptions(log.Default(), stdr.Options {
Verbosity: &lvl,
}) ^ whereas this has the effect of "everything that noisyService logs > lvl5 will be filtered out" My particular use-case is to define a few log level constants (e.g. Default, Debug, Trace), and then use the Verbosity setting to decide what the cut-off point is for a given service. For example, I might be debugging an issue and want to enable Debug logs everywhere except for noisyService, which is just really spammy at that level. If I were to increase the V-level of the logger, then everything noisyService logs will be made less important, including perhaps the important logs that were at V0 before. There's a good chance this is me attempting some kind of anti-pattern with logr, so let me know if that's the case :) |
I see. You really want per-logger verbosity. It seems very tedious to manage in a real application - if you have more than two or three of these you have to go an update them all. That said, I'll reconsider it. |
Will there be a new release that includes this feature? |
Yes, we're discussing a couple other changes, but mostly I need to make
time to go thru the motions.
…On Tue, Dec 20, 2022 at 9:41 AM Richard Fuchs ***@***.***> wrote:
Will there be a new release that includes this feature?
—
Reply to this email directly, view it on GitHub
<#26 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKWAVBUYMMLVAIVPL6ZPOLWOHVU5ANCNFSM5TFDHKXQ>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Other loggers included with logr already support this (e.g.
testr
). A pointer is used for Verbosity in order to provide differentiation of the zero value of Verbosity from log level 0.Usage example: