-
Notifications
You must be signed in to change notification settings - Fork 0
/
rh-logrus-adapter.go
42 lines (32 loc) · 1006 Bytes
/
rh-logrus-adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
}