Skip to content

Commit

Permalink
don't set logger default level twice (crowdsecurity#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Mar 10, 2022
1 parent aca37a3 commit e7de05d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions plugins/notifications/email/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

var logger hclog.Logger = hclog.New(&hclog.LoggerOptions{
Name: "email-plugin",
Level: hclog.LevelFromString("DEBUG"),
Level: hclog.LevelFromString("INFO"),
Output: os.Stderr,
JSONFormat: true,
})
Expand Down Expand Up @@ -97,11 +97,11 @@ func (n *EmailPlugin) Notify(ctx context.Context, notification *protobufs.Notifi
return nil, fmt.Errorf("invalid plugin config name %s", notification.Name)
}
cfg := n.ConfigByName[notification.Name]

if cfg.LogLevel != nil && *cfg.LogLevel != "" {
logger.SetLevel(hclog.LevelFromString(*cfg.LogLevel))
} else {
logger.SetLevel(hclog.Info)
}

logger = logger.Named(cfg.Name)
logger.Debug("got notification")

Expand Down
5 changes: 2 additions & 3 deletions plugins/notifications/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type HTTPPlugin struct {

var logger hclog.Logger = hclog.New(&hclog.LoggerOptions{
Name: "http-plugin",
Level: hclog.LevelFromString("DEBUG"),
Level: hclog.LevelFromString("INFO"),
Output: os.Stderr,
JSONFormat: true,
})
Expand All @@ -40,10 +40,9 @@ func (s *HTTPPlugin) Notify(ctx context.Context, notification *protobufs.Notific
return nil, fmt.Errorf("invalid plugin config name %s", notification.Name)
}
cfg := s.PluginConfigByName[notification.Name]

if cfg.LogLevel != nil && *cfg.LogLevel != "" {
logger.SetLevel(hclog.LevelFromString(*cfg.LogLevel))
} else {
logger.SetLevel(hclog.Info)
}

logger.Info(fmt.Sprintf("received signal for %s config", notification.Name))
Expand Down
5 changes: 2 additions & 3 deletions plugins/notifications/slack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Notify struct {

var logger hclog.Logger = hclog.New(&hclog.LoggerOptions{
Name: "slack-plugin",
Level: hclog.LevelFromString("DEBUG"),
Level: hclog.LevelFromString("INFO"),
Output: os.Stderr,
JSONFormat: true,
})
Expand All @@ -34,10 +34,9 @@ func (n *Notify) Notify(ctx context.Context, notification *protobufs.Notificatio
return nil, fmt.Errorf("invalid plugin config name %s", notification.Name)
}
cfg := n.ConfigByName[notification.Name]

if cfg.LogLevel != nil && *cfg.LogLevel != "" {
logger.SetLevel(hclog.LevelFromString(*cfg.LogLevel))
} else {
logger.SetLevel(hclog.Info)
}

logger.Info(fmt.Sprintf("found notify signal for %s config", notification.Name))
Expand Down
6 changes: 3 additions & 3 deletions plugins/notifications/splunk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var logger hclog.Logger = hclog.New(&hclog.LoggerOptions{
Name: "splunk-plugin",
Level: hclog.LevelFromString("DEBUG"),
Level: hclog.LevelFromString("INFO"),
Output: os.Stderr,
JSONFormat: true,
})
Expand All @@ -45,11 +45,11 @@ func (s *Splunk) Notify(ctx context.Context, notification *protobufs.Notificatio
return &protobufs.Empty{}, fmt.Errorf("splunk invalid config name %s", notification.Name)
}
cfg := s.PluginConfigByName[notification.Name]

if cfg.LogLevel != nil && *cfg.LogLevel != "" {
logger.SetLevel(hclog.LevelFromString(*cfg.LogLevel))
} else {
logger.SetLevel(hclog.Info)
}

logger.Info(fmt.Sprintf("received notify signal for %s config", notification.Name))

p := Payload{Event: notification.Text}
Expand Down

0 comments on commit e7de05d

Please sign in to comment.