aboutsummaryrefslogtreecommitdiff
path: root/internal/log_unix.go
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-12-08 08:24:06 +0100
committerGitHub <noreply@github.com>2022-12-08 08:24:06 +0100
commit27a1dea5225c828ad787098aadafa83ed73c4940 (patch)
treec5844d7118a69b8cd17b0636182f6c57d0c16bf0 /internal/log_unix.go
parentba2ffb7da9b86b64dc8091d90645ab80cf2831db (diff)
Fix issue with multiple/duplicate log entries during tests (#2906)
Diffstat (limited to 'internal/log_unix.go')
-rw-r--r--internal/log_unix.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/internal/log_unix.go b/internal/log_unix.go
index 75332af7..b38e7c2e 100644
--- a/internal/log_unix.go
+++ b/internal/log_unix.go
@@ -22,16 +22,16 @@ import (
"log/syslog"
"github.com/MFAshby/stdemuxerhook"
- "github.com/matrix-org/dendrite/setup/config"
"github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
+
+ "github.com/matrix-org/dendrite/setup/config"
)
// SetupHookLogging 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) {
- stdLogAdded := false
for _, hook := range hooks {
// Check we received a proper logging level
level, err := logrus.ParseLevel(hook.Level)
@@ -54,14 +54,11 @@ func SetupHookLogging(hooks []config.LogrusHook, componentName string) {
setupSyslogHook(hook, level, componentName)
case "std":
setupStdLogHook(level)
- stdLogAdded = true
default:
logrus.Fatalf("Unrecognised logging hook type: %s", hook.Type)
}
}
- if !stdLogAdded {
- setupStdLogHook(logrus.InfoLevel)
- }
+ setupStdLogHook(logrus.InfoLevel)
// Hooks are now configured for stdout/err, so throw away the default logger output
logrus.SetOutput(io.Discard)
}
@@ -88,7 +85,11 @@ func checkSyslogHookParams(params map[string]interface{}) {
}
func setupStdLogHook(level logrus.Level) {
+ if stdLevelLogAdded[level] {
+ return
+ }
logrus.AddHook(&logLevelHook{level, stdemuxerhook.New(logrus.StandardLogger())})
+ stdLevelLogAdded[level] = true
}
func setupSyslogHook(hook config.LogrusHook, level logrus.Level, componentName string) {