onrik / logrus

Hooks for logrus logging
MIT License
122 stars 30 forks source link

Add support for setting levels to hooks #11

Open montanaflynn opened 5 years ago

montanaflynn commented 5 years ago

I would like to use filename hook but only for errors, other hooks I use (logrus_sentry, logrus-papertrail-hook) expose a SetLevels method for this like so:

hook.SetLevels([]logrus.Level{
    logrus.PanicLevel,
    logrus.FatalLevel,
    logrus.ErrorLevel,
})
logger.AddHook(hook)
onrik commented 5 years ago

What is your cases for change levels after hook created?

montanaflynn commented 5 years ago

@onrik my use case is wanting to only include the filename for certain levels.

I found a pattern in other hooks that support the SetLevels method so I assumed that was not supported but now that I looked at the code I see that NewHook takes levels as an arg.

Maybe you could add links to godoc to help others as well:

https://godoc.org/github.com/onrik/logrus/filename