-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapex_test.go
83 lines (66 loc) · 1.52 KB
/
apex_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
package bench
import (
"io"
apex "github.com/apex/log"
"github.com/apex/log/handlers/json"
)
func apexFields() apex.Fields {
return apex.Fields{
"bytes": ctxBodyBytes,
"request": ctxRequest,
"elapsed_time_ms": ctxTimeElapsedMs,
"user": ctxUser,
"now": ctxTime,
"months": ctxMonths,
"primes": ctxFirst10Primes,
"users": ctxUsers,
"error": ctxErr,
}
}
func newApex(w io.Writer) *apex.Logger {
writer := json.New(w)
return &apex.Logger{
Handler: writer,
Level: apex.InfoLevel,
}
}
type apexBench struct {
l apex.Interface
}
func (b *apexBench) new(w io.Writer) logBenchmark {
return &apexBench{
l: newApex(w),
}
}
func (b *apexBench) newWithCtx(w io.Writer) logBenchmark {
return &apexBench{
l: newApex(w).WithFields(apexFields()),
}
}
func (b *apexBench) name() string {
return "Apex"
}
func (b *apexBench) logEvent(msg string) {
b.l.Info(msg)
}
func (b *apexBench) logEventFmt(msg string, args ...any) {
b.l.Infof(msg, args...)
}
func (b *apexBench) logEventCtx(msg string) {
b.l.WithFields(apexFields()).Info(msg)
}
func (b *apexBench) logEventCtxWeak(msg string) {
b.logEventCtx(msg)
}
func (b *apexBench) logDisabled(msg string) {
b.l.Debug(msg)
}
func (b *apexBench) logDisabledFmt(msg string, args ...any) {
b.l.Debugf(msg, args...)
}
func (b *apexBench) logDisabledCtx(msg string) {
b.l.WithFields(apexFields()).Debug(msg)
}
func (b *apexBench) logDisabledCtxWeak(msg string) {
b.logDisabledCtx(msg)
}