Skip to content

Commit

Permalink
crowdsec: avoid writing errors twice when log_media=stdout
Browse files Browse the repository at this point in the history
fix #2729
for level=fatal
  • Loading branch information
mmetc committed Mar 7, 2024
1 parent e611d01 commit b2c6151
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cmd/crowdsec/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ type ConditionalHook struct {
}

func (hook *ConditionalHook) Fire(entry *log.Entry) error {
if hook.Enabled {
line, err := entry.String()
if err != nil {
return err
}

_, err = hook.Writer.Write([]byte(line))
// don't log if the hook is disabled
// or if the level is fatal (the standard logger will handle it)

if !hook.Enabled || entry.Level == log.FatalLevel {
return nil
}

line, err := entry.String()
if err != nil {
return err
}

return nil
_, err = hook.Writer.Write([]byte(line))

return err
}

func (hook *ConditionalHook) Levels() []log.Level {
Expand Down

0 comments on commit b2c6151

Please sign in to comment.