-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlogrus_test.go
131 lines (105 loc) · 2.96 KB
/
logrus_test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package logbench
import (
"io"
"time"
"github.com/sirupsen/logrus"
)
func init() {
tests["Logrus"] = logrusTester{}
}
type logrusTester struct {
l logrus.FieldLogger
}
var (
_ logTesterArray = (*logrusTester)(nil)
)
func (logrusTester) newLogger(out io.Writer, disabled bool) logTester {
lvl := logrus.DebugLevel
if disabled {
lvl = logrus.PanicLevel
}
return logrusTester{&logrus.Logger{
Out: out,
Formatter: &logrus.JSONFormatter{
DisableTimestamp: true,
FieldMap: logrus.FieldMap{
logrus.FieldKeyTime: "",
logrus.FieldKeyMsg: "message",
},
},
Hooks: make(logrus.LevelHooks),
Level: lvl,
}}
}
func (t logrusTester) logMsg(msg string) {
t.l.Info(msg)
}
func (t logrusTester) logFormat(format string, v ...interface{}) bool {
t.l.Infof(format, v...)
return true
}
func (t logrusTester) withContext(context map[string]interface{}) (logTester, bool) {
return logrusTester{t.l.WithFields(context)}, true
}
func (t logrusTester) logBool(msg, key string, value bool) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logInt(msg, key string, value int) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logFloat32(msg, key string, value float32) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logFloat64(msg, key string, value float64) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logTime(msg, key string, value time.Time) bool {
return false
}
func (t logrusTester) logDuration(msg, key string, value time.Duration) bool {
return false
}
func (t logrusTester) logError(msg, key string, value error) bool {
return false
}
func (t logrusTester) logString(msg, key string, value string) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logObject(msg, key string, value *obj) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logBools(msg, key string, value []bool) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logInts(msg, key string, value []int) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logFloats32(msg, key string, value []float32) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logFloats64(msg, key string, value []float64) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}
func (t logrusTester) logTimes(msg, key string, value []time.Time) bool {
return false
}
func (t logrusTester) logDurations(msg, key string, value []time.Duration) bool {
return false
}
func (t logrusTester) logErrors(msg, key string, value []error) bool {
return false
}
func (t logrusTester) logStrings(msg, key string, value []string) bool {
t.l.WithFields(logrus.Fields{key: value}).Info(msg)
return true
}