From f886fbc9170181bd282da16c23c457fa61912656 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Tue, 7 Dec 2021 11:51:47 +0000 Subject: [PATCH] Revert logging formatter changes to log.go, base.go. 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 https://github.com/matrix-org/dendrite/pull/2060#discussion_r762557679 --- internal/log.go | 15 +++++++++++++++ internal/log_unix.go | 11 ----------- setup/base/base.go | 1 + 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/internal/log.go b/internal/log.go index ea44e22b5..bba0ac6e6 100644 --- a/internal/log.go +++ b/internal/log.go @@ -91,6 +91,21 @@ func SetupPprof() { } } +// SetupStdLogging configures the logging format to standard output. Typically, it is called when the config is not yet loaded. +func SetupStdLogging() { + logrus.SetReportCaller(true) + logrus.SetFormatter(&utcFormatter{ + &logrus.TextFormatter{ + TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00", + FullTimestamp: true, + DisableColors: false, + DisableTimestamp: false, + QuoteEmptyFields: true, + CallerPrettyfier: callerPrettyfier, + }, + }) +} + // File type hooks should be provided a path to a directory to store log files func checkFileHookParams(params map[string]interface{}) { path, ok := params["path"] diff --git a/internal/log_unix.go b/internal/log_unix.go index 44cb75beb..27d9a8fe6 100644 --- a/internal/log_unix.go +++ b/internal/log_unix.go @@ -30,17 +30,6 @@ import ( // 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) { - logrus.SetReportCaller(true) - logrus.SetFormatter(&utcFormatter{ - &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 diff --git a/setup/base/base.go b/setup/base/base.go index 1249e1422..9ba88bef7 100644 --- a/setup/base/base.go +++ b/setup/base/base.go @@ -123,6 +123,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base logrus.Fatalf("Failed to start due to configuration errors") } + internal.SetupStdLogging() internal.SetupHookLogging(cfg.Logging, componentName) internal.SetupPprof()