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

Added std type to logging config. #2060

Merged
merged 7 commits into from Dec 16, 2021
Merged

Added std type to logging config. #2060

merged 7 commits into from Dec 16, 2021

Conversation

MFAshby
Copy link
Contributor

@MFAshby MFAshby commented Nov 27, 2021

Added demux-ing of logging to stdout/err working around
sirupsen/logrus#403

Turned off the default logging in favour of using hooks always.

Added fallback, if no stdout/err logger was configured, add one
automatically. This prevents unexpected lack of logging after an
upgrade in case the user's configuration file is not updated.

Fixes: #2054

Pull Request Checklist

✔️
  • I have added any new tests that need to pass to sytest-whitelist as specified in docs/sytest.md
  • Pull request includes a sign off

Signed-off-by: Your Name <your@email.example.org>

Added demux-ing of logging to stdout/err working around
sirupsen/logrus#403

Turned off the default logging in favour of using hooks always.

Added fallback, if no stdout/err logger was configured, add one
automatically. This prevents unexpected lack of logging after an
upgrade in case the user's configuration file is not updated.

Fixes: #2054
Signed-off-by: Martin Ashby <martin@ashbysoft.com>
// If something fails here it means that the logging was improperly configured,
// so we just exit with the error
func SetupHookLogging(hooks []config.LogrusHook, componentName string) {
func SetupLogging(hooks []config.LogrusHook, componentName string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming this function will break building on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. Reverting this.

Copy link
Contributor

@S7evinK S7evinK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in internal/log.go and setup/base/base.go aren't necessary and like the function name will break building on Windows.

@@ -29,6 +31,17 @@ import (
// so we just exit with the error
func SetupHookLogging(hooks []config.LogrusHook, componentName string) {
logrus.SetReportCaller(true)
logrus.SetFormatter(&utcFormatter{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you move this back to internal/log.go and undo the changes to setup/base/base.go, I'm happy with this. :)

The same formatting should be applied on both windows and unix, so it
makes sense to keep it in files which are shared between both platforms.

Fixes
#2060 (comment)
default:
logrus.Fatalf("Unrecognised logging hook type: %s", hook.Type)
}
}
if !stdLogAdded {
logrus.Info("No std logger config found. Enabling at INFO level by default")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure if we need to log this? It just seems like noise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I was pretty much just using it for a quick test. Could take it out.

setupStdLogHook(logrus.InfoLevel)
}
// Hooks are now configured for stdout/err, so throw away the default logger output
logrus.SetOutput(ioutil.Discard)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat wondering whether something like logrus.SetLevel(logrus.PanicLevel) is better here, since otherwise we're allocating log buffers just to write them to a discarding writer, which seems like a waste of allocations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure: wouldn't this set the level for all loggers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to be honest. Just a thought / might be worth trying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work, I'm afraid. Calling SetLevel(logrus.PanicLevel) simply disables all logging

This explains why this code here is required:

if logrus.GetLevel() < level {

I think this is just a limitation of logrus.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unfortunate. We'll just have to go with io.Discard anyway then.

@MFAshby MFAshby requested a review from a team as a code owner December 13, 2021 23:00
@neilalexander neilalexander merged commit e5a5be9 into matrix-org:master Dec 16, 2021
@MFAshby MFAshby deleted the stdout_loglevel branch December 16, 2021 16:23
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

Successfully merging this pull request may close these issues.

Allow to set debug level for dendrite STDERR logging
3 participants