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 Request: Assign Levels for firing. #3

Open
tlbignerd opened this issue Apr 20, 2018 · 1 comment
Open

Feature Request: Assign Levels for firing. #3

tlbignerd opened this issue Apr 20, 2018 · 1 comment

Comments

@tlbignerd
Copy link

Currently the database will log for every event level except for panic, as seen here:
func (hook *Hook) Levels() []logrus.Level { return []logrus.Level{ logrus.FatalLevel, logrus.ErrorLevel, logrus.WarnLevel, logrus.InfoLevel, logrus.DebugLevel, } }

It would be ideal if this method can be provided externally with something like the following:

func (h *Hook) init() { h.Levels = func (hook *Hook) Levels() []logrus.Level { return []logrus.Level{ logrus.FatalLevel, logrus.ErrorLevel, logrus.WarnLevel, logrus.InfoLevel, logrus.DebugLevel, } } }

Then in my caller I can update Levels with something like:
hook := pglogrus.NewAsyncHook(db.DB, map[string]interface{}{}) hook.Levels = func() []logrus.Level { topLevel := int(settings.Log.DbLogLevel) + 1 return logrus.AllLevels[0:topLevel] } l.AddHook(hook)

Alternatively it would be good if we can assign levels at declaration to a slice, and that could be used during execution. Something like the following:

type Hook struct { ... LogLevels []Level }

@gravis
Copy link
Member

gravis commented Apr 27, 2018

Thanks for submitting this. We never implemented that, because we never had the need. But I like the idea, and will accept any merge request with tests :)

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

2 participants