Skip to content
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

Closed
vith opened this issue May 11, 2018 · 4 comments
Closed

Feature proposal: optional debug log sections #61

vith opened this issue May 11, 2018 · 4 comments

Comments

@vith
Copy link

vith commented May 11, 2018

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

log.Section("foo").Debug().Int("magic", n).Msg("Made some magic")

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
@rs
Copy link
Owner

rs commented May 12, 2018

Sounds like a good idea. Do you want to give it a try?

ccamel added a commit to ccamel/zerolog that referenced this issue May 16, 2018
ccamel added a commit to ccamel/zerolog that referenced this issue May 16, 2018
ccamel added a commit to ccamel/zerolog that referenced this issue May 17, 2018
@JDiPierro
Copy link

👍! I was about to open an issue requesting "Trace" as a log level but this would work very well in place of that.

@deinspanjer
Copy link

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:

if log.Enabled(LoggingTagOne, LoggingTagTwo) {
  fields := logrus.Fields{"A": getA(), "B": true}
  log.WithFields(fields).Debug(...)
}

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.

@marco-m
Copy link

marco-m commented Jul 1, 2019

I believe that this is normally called subsystem logging. I am writing this down to help people googling for it :-)

@rs rs closed this as completed Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants