-
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 Logger.Enabled method #617
Conversation
You already have Enabled at the event level. Adding another similar method at the logger level will be confusing. |
Are you suggesting to name it differently? Because I think that is a plus to have the same name, because it is semantically the same: at the event level |
I'm hesitant to add it as it creates multiple ways to do a similar thing. |
So how does can one check if Logger is a Nop or zero logger, so in practice a disabled logger, in any other way? (If this would introduce multiple ways to do it?) One does not have access to |
The idea is that you get this via the event's |
But I need before. To even know if I should install hlog middleware. If logger is Nop there is no point installing hlog middleware. |
Handlers are generally installed unconditionally so they can start logging if a logger is enabled at runtime. If you want to conditionally install them, you could use the same condition used to disable your logger. |
I mean, I allow users to pass |
The logger is passed to handlers via context. The state of the logger during app init might not be its state for the lifetime of the app. This is sort of app dependent so the mechanism to decide how to install those handlers should probably be as well. |
I disagree for my particular case, my library controls both the context creation and middleware installation. But I will not push this further. Thanks for keeping arguing your point. |
It seems I can do the same with: if l := logger.Sample(nil); l.Log().Enabled() {
// ...
} |
This works with Nop and zero Logger. It allows one to skip some initialization if logger is disabled (e.g., skip installing hlog middleware).