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
Logger.SetLevel #503
Comments
👍 Had a similar situation. Perhaps instead &log.Logger{
Out: os.Stderr,
Formatter: new(log.TextFormatter),
Hooks: make(log.LevelHooks),
Level: log.DebugLevel,
} |
Unfortunately that doesn't work for us, because we need to be able to set the log level based on the configuration file that's passed. The only way to do that and also preserve the @sirupsen I'm happy to put together a PR for this if it's something you're interested in adding. |
Yes, that's still a limitation - can't change the log level after it has been set,. Would be interested in testing out your PR too. |
This makes sense, feel free to propose a PR upstream. |
@ChimeraCoder @sirupsen |
Export logger's set level function to address #503.
This has shipped 🎉 |
…ure/add_color_setting_support_in_text_formatter * 'master' of https://github.com/sirupsen/logrus: (21 commits) Improve logrus.Entry.Level documentation remove QuoteCharacter option add changelog entry about making SetLevel public Mention quoting bugfix in CHANGELOG Error is not a special case anymore Generalize test case Reduce duplicate code Quote non-string values if necessary remove ^ from custom quote characters readme: link to comment on casing Mention bugfix in changelog Extract quoting into separate method Use custom quote char and escape it Safely format data when printing Export logger's set level function to address sirupsen#503. fix casing readme: add note about lookign for maintainers Allow more chars in unquoted text formatter output Update hook name README: add hook for Mattermost ... # Conflicts: # text_formatter.go
🎉 |
Export logger's set level function to address sirupsen#503.
It appears that we can't (safely) configure the loglevels of loggers except for the standard logger.
For the standard logger, we can use the
logrus.SetLevel
method, which protects the level with a mutex, but this mutex is unexported. So if we setvar log = logrus.New()
in our application (which is recommended in the docs), we actually can't configure the log level.The only other thing we can do is to call
SetLevel
on the standard logger and then assigning it:but that's a bit clumsier, and it also means we're restricted to just using the standard logger.
Am I missing an alternative?
The text was updated successfully, but these errors were encountered: