Skip to content

Commit

Permalink
Update pkg/tools/log/logruslogger/levelchange.go
Browse files Browse the repository at this point in the history
Co-authored-by: Denis Tingaikin <[email protected]>
Signed-off-by: Arpad Kiss <[email protected]>
  • Loading branch information
arp-est and denis-tingaikin authored Oct 4, 2024
1 parent 619e688 commit b5a6faa
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions pkg/tools/log/logruslogger/levelchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,19 @@ import (

// SetupLevelChangeOnSignal sets the loglevel to the one specified in the map when a signal assotiated to it arrives
func SetupLevelChangeOnSignal(ctx context.Context, signals map[os.Signal]logrus.Level) {
if len(signals) < 2 {
log.FromContext(ctx).Info("map size < 2, disabling loglevel change on signal")
return
}
vals := []logrus.Level{}
for _, v := range signals {
vals = append(vals, v)
}
sort.Slice(vals, func(i, j int) bool { return i < j })
for i := 0; i < len(vals)-1; i++ {
if vals[i] == vals[i+1] {
log.FromContext(ctx).Info("duplicate values found in map, disabling loglevel change on signal")
return
}
}
var currentLevelCount int

for _, v := range signals{
if v == logrus.GetLevel() {
currentLevelCount++
}
}

if currentLevelCount == len(signals) {

log.FromContext(ctx).WithField("logruslogger","SetupLevelChangeOnSignal").Warn("detected that log level will never changed, disabling loglevel change on signal")
return
}
sigChannel := make(chan os.Signal, len(signals))
for sig := range signals {
signal.Notify(sigChannel, sig)
Expand Down

0 comments on commit b5a6faa

Please sign in to comment.