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 2c9bbea
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions 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
for _, hooks := range log.Hooks {
for _, hook := range hooks {
cloned.Hooks.Add(hook)

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

for level, hooks := range log.Hooks {
for i, hook := range hooks {
globalHooks[hooks[i]] = true
}
}

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

return cloned
}

0 comments on commit 2c9bbea

Please sign in to comment.