Skip to content

Commit

Permalink
Prevent adding one hook multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sumin committed Mar 6, 2024
1 parent 9295f25 commit 75e60ed
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,18 @@ func cloneGlobalLogger() *logrus.Logger {
cloned.SetLevel(log.Level)
cloned.SetOutput(log.Out)
cloned.ExitFunc = log.ExitFunc

globalHooks := make(map[logrus.Hook]bool)

for _, hooks := range log.Hooks {
for _, hook := range hooks {
cloned.Hooks.Add(hook)
globalHooks[hook] = true
}
}

for hook, _ := range globalHooks {
cloned.Hooks.Add(hook)
}

return cloned
}

0 comments on commit 75e60ed

Please sign in to comment.