Commit f80a38f3 authored by Alessio Caiazza's avatar Alessio Caiazza 💡
Browse files

Fix data race in helpers.MakeFatalToPanic()

parent 6af4fbe1
Pipeline #29534376 passed with stages
in 27 minutes and 37 seconds
......@@ -24,22 +24,13 @@ func (s *fatalLogHook) Fire(e *logrus.Entry) error {
}
func MakeFatalToPanic() func() {
hook := &fatalLogHook{
output: logrus.StandardLogger().Out,
}
logrus.AddHook(hook)
removeHook := func() {
for level, levelHooks := range logrus.StandardLogger().Hooks {
hooks := []logrus.Hook{}
for _, existingHook := range levelHooks {
if existingHook != hook {
hooks = append(hooks, existingHook)
}
}
logrus.StandardLogger().Hooks[level] = hooks
}
}
logger := logrus.StandardLogger()
hooks := make(logrus.LevelHooks)
return removeHook
hooks.Add(&fatalLogHook{output: logger.Out})
oldHooks := logger.ReplaceHooks(hooks)
return func() {
logger.ReplaceHooks(oldHooks)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment