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.
This commit is contained in:
Diaa Sami 2022-03-30 12:37:17 +02:00 committed by Diaa Sami
parent e6475d0e0e
commit ed5cd56c5a

View file

@ -1,6 +1,8 @@
package koji
import (
"strings"
"github.com/sirupsen/logrus"
)
@ -8,6 +10,8 @@ type LeveledLogrus struct {
*logrus.Logger
}
const monitoringKeyword = "retrying"
func fields(keysAndValues ...interface{}) map[string]interface{} {
fields := make(map[string]interface{})
@ -26,7 +30,11 @@ func (l *LeveledLogrus) Info(msg string, keysAndValues ...interface{}) {
l.WithFields(fields(keysAndValues...)).Info(msg)
}
func (l *LeveledLogrus) Debug(msg string, keysAndValues ...interface{}) {
l.WithFields(fields(keysAndValues...)).Debug(msg)
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{}) {