debian-forge-composer/internal/upload/koji/rh-logrus-adapter.go
Diaa Sami ed5cd56c5a koji: promote relevant logs to Info for monitoring
Add support for promoting certain `Debug` log messages to `Info` so we
can monitor them while the logging level set to `Info`, having it set
to Debug is far too noisy.
2022-04-05 23:48:30 +02:00

42 lines
1,006 B
Go

package koji
import (
"strings"
"github.com/sirupsen/logrus"
)
type LeveledLogrus struct {
*logrus.Logger
}
const monitoringKeyword = "retrying"
func fields(keysAndValues ...interface{}) map[string]interface{} {
fields := make(map[string]interface{})
for i := 0; i < len(keysAndValues)-1; i += 2 {
fields[keysAndValues[i].(string)] = keysAndValues[i+1]
}
return fields
}
func (l *LeveledLogrus) Error(msg string, keysAndValues ...interface{}) {
l.WithFields(fields(keysAndValues...)).Error(msg)
}
func (l *LeveledLogrus) Info(msg string, keysAndValues ...interface{}) {
l.WithFields(fields(keysAndValues...)).Info(msg)
}
func (l *LeveledLogrus) Debug(msg string, keysAndValues ...interface{}) {
if strings.Contains(msg, monitoringKeyword) {
l.WithFields(fields(keysAndValues...)).Info(msg)
} else {
l.WithFields(fields(keysAndValues...)).Debug(msg)
}
}
func (l *LeveledLogrus) Warn(msg string, keysAndValues ...interface{}) {
l.WithFields(fields(keysAndValues...)).Warn(msg)
}