-
-
Notifications
You must be signed in to change notification settings - Fork 675
Added std type to logging config. #2060
Changes from 1 commit
779e4c0
8c862cd
abd370a
f886fbc
350954c
c4d91fd
c1646b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -17,18 +17,31 @@ | |||
package internal | ||||
|
||||
import ( | ||||
"io/ioutil" | ||||
"log/syslog" | ||||
|
||||
"github.com/MFAshby/stdemuxerhook" | ||||
"github.com/matrix-org/dendrite/setup/config" | ||||
"github.com/sirupsen/logrus" | ||||
lSyslog "github.com/sirupsen/logrus/hooks/syslog" | ||||
) | ||||
|
||||
// SetupHookLogging configures the logging hooks defined in the configuration. | ||||
// SetupLogging configures the logging hooks defined in the configuration. | ||||
// 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) { | ||||
logrus.SetReportCaller(true) | ||||
logrus.SetFormatter(&utcFormatter{ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you move this back to |
||||
&logrus.TextFormatter{ | ||||
TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00", | ||||
FullTimestamp: true, | ||||
DisableColors: false, | ||||
DisableTimestamp: false, | ||||
QuoteEmptyFields: true, | ||||
CallerPrettyfier: callerPrettyfier, | ||||
}, | ||||
}) | ||||
stdLogAdded := false | ||||
for _, hook := range hooks { | ||||
// Check we received a proper logging level | ||||
level, err := logrus.ParseLevel(hook.Level) | ||||
|
@@ -49,10 +62,19 @@ func SetupHookLogging(hooks []config.LogrusHook, componentName string) { | |||
case "syslog": | ||||
checkSyslogHookParams(hook.Params) | ||||
setupSyslogHook(hook, level, componentName) | ||||
case "std": | ||||
setupStdLogHook(level) | ||||
stdLogAdded = true | ||||
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") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm somewhat wondering whether something like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can try it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't work, I'm afraid. Calling This explains why this code here is required: Line 41 in 61406a6
I think this is just a limitation of logrus. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's unfortunate. We'll just have to go with |
||||
} | ||||
|
||||
func checkSyslogHookParams(params map[string]interface{}) { | ||||
|
@@ -76,6 +98,10 @@ func checkSyslogHookParams(params map[string]interface{}) { | |||
|
||||
} | ||||
|
||||
func setupStdLogHook(level logrus.Level) { | ||||
logrus.AddHook(&logLevelHook{level, stdemuxerhook.New(logrus.StandardLogger())}) | ||||
} | ||||
|
||||
func setupSyslogHook(hook config.LogrusHook, level logrus.Level, componentName string) { | ||||
syslogHook, err := lSyslog.NewSyslogHook(hook.Params["protocol"].(string), hook.Params["address"].(string), syslog.LOG_INFO, componentName) | ||||
if err == nil { | ||||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. Reverting this.