-
Notifications
You must be signed in to change notification settings - Fork 572
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
Feature proposal: optional debug log sections #61
Comments
Sounds like a good idea. Do you want to give it a try? |
👍! I was about to open an issue requesting "Trace" as a log level but this would work very well in place of that. |
In a project I'm writing that currently uses logrus, I have a conditional logger that wraps it and lets the application use tests such as:
Having the if block was important to prevent a bunch of unnecessary allocation, execution if it would be wasted, and it provides a nice ability to selectively log for different parts of the app on the fly. About to open source the project and happy to point you at it if it might be handy. I added a todo to look at replacing logrus with zerolog as I'm not extremely happy with it so far. |
I believe that this is normally called subsystem logging. I am writing this down to help people googling for it :-) |
A pattern for logging I found handy in the NodeJS world is the
util.debuglog()
method.Basically you have named sections of the debug log that you can enable the output for individually instead of turning on a firehose of debugging output from every part of the application at once.
So it could work something like
and the output would be enabled by an environment variable:
$ DEBUG_SECTION=foo ./app
or alternatively through a setting on the logger in Go. Basically bypassing the Level check for events that have an explicitly enabled section.
To make it even more powerful it could allow specifying any output level for a given section rather than only being for Debug level events, and/or support wildcards for sections that have a hierarchy of name prefixes.
$ LOG_SECTIONS="foo=debug,bar*=info" ./app
The text was updated successfully, but these errors were encountered: