-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathzerolog_test.go
136 lines (108 loc) · 3.1 KB
/
zerolog_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
132
133
134
135
136
package logbench
import (
"io"
"time"
"github.com/rs/zerolog"
)
func init() {
zerolog.TimeFieldFormat = ""
zerolog.DurationFieldInteger = true
zerolog.MessageFieldName = "message"
tests["Zerolog"] = zerologTester{}
}
func (o obj) MarshalZerologObject(e *zerolog.Event) {
e.Str("name", o.Name).
Int("count", o.Count).
Bool("enabled", o.Enabled)
}
type zerologTester struct {
l zerolog.Logger
}
var (
_ logTesterArray = (*zerologTester)(nil)
)
func (zerologTester) newLogger(out io.Writer, disabled bool) logTester {
lvl := zerolog.DebugLevel
if disabled {
lvl = zerolog.Disabled
}
return zerologTester{zerolog.New(out).Level(lvl)}
}
func (t zerologTester) logMsg(msg string) {
t.l.Info().Msg(msg)
}
func (t zerologTester) logFormat(format string, v ...interface{}) bool {
t.l.Info().Msgf(format, v...)
return true
}
func (t zerologTester) withContext(context map[string]interface{}) (logTester, bool) {
return zerologTester{t.l.With().Fields(context).Logger()}, true
}
func (t zerologTester) logBool(msg, key string, value bool) bool {
t.l.Info().Bool(key, value).Msg(msg)
return true
}
func (t zerologTester) logInt(msg, key string, value int) bool {
t.l.Info().Int(key, value).Msg(msg)
return true
}
func (t zerologTester) logFloat32(msg, key string, value float32) bool {
t.l.Info().Float32(key, value).Msg(msg)
return true
}
func (t zerologTester) logFloat64(msg, key string, value float64) bool {
t.l.Info().Float64(key, value).Msg(msg)
return true
}
func (t zerologTester) logTime(msg, key string, value time.Time) bool {
t.l.Info().Time(key, value).Msg(msg)
return true
}
func (t zerologTester) logDuration(msg, key string, value time.Duration) bool {
t.l.Info().Dur(key, value).Msg(msg)
return true
}
func (t zerologTester) logError(msg, key string, value error) bool {
t.l.Info().AnErr(key, value).Msg(msg)
return true
}
func (t zerologTester) logString(msg, key string, value string) bool {
t.l.Info().Str(key, value).Msg(msg)
return true
}
func (t zerologTester) logObject(msg, key string, value *obj) bool {
t.l.Info().Object(key, value).Msg(msg)
return true
}
func (t zerologTester) logBools(msg, key string, value []bool) bool {
t.l.Info().Bools(key, value).Msg(msg)
return true
}
func (t zerologTester) logInts(msg, key string, value []int) bool {
t.l.Info().Ints(key, value).Msg(msg)
return true
}
func (t zerologTester) logFloats32(msg, key string, value []float32) bool {
t.l.Info().Floats32(key, value).Msg(msg)
return true
}
func (t zerologTester) logFloats64(msg, key string, value []float64) bool {
t.l.Info().Floats64(key, value).Msg(msg)
return true
}
func (t zerologTester) logTimes(msg, key string, value []time.Time) bool {
t.l.Info().Times(key, value).Msg(msg)
return true
}
func (t zerologTester) logDurations(msg, key string, value []time.Duration) bool {
t.l.Info().Durs(key, value).Msg(msg)
return true
}
func (t zerologTester) logErrors(msg, key string, value []error) bool {
t.l.Info().Errs(key, value).Msg(msg)
return true
}
func (t zerologTester) logStrings(msg, key string, value []string) bool {
t.l.Info().Strs(key, value).Msg(msg)
return true
}