-
Notifications
You must be signed in to change notification settings - Fork 10
/
slf_logger_test.go
65 lines (54 loc) · 1.29 KB
/
slf_logger_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
package slog
import (
"testing"
)
// BenchmarkNoLog-12 50000000 31.8 ns/op 32 B/op 1 allocs/op
func BenchmarkNoLog(b *testing.B) {
SetLevel(WarnLevel)
log := GetLogger()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
log.Info("hahahhhhh %v", nil)
}
}
// BenchmarkNoLog2-12 500000000 3.34 ns/op 0 B/op 0 allocs/op
func BenchmarkNoLog2(b *testing.B) {
SetLevel(WarnLevel)
log := GetLogger()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if log.IsInfoEnabled() {
log.Info("hahahhhhh %v", nil)
}
}
}
func TestLoggerFields(t *testing.T) {
log1 := GetLogger()
log1.BindFields(Fields{"age": 18})
log1.Debug("hell1")
log2 := log1.WithFields(Fields{"score": 100.0})
log2.Info("hello2")
log2.WithFields(Fields{"fav": "basketball"}).Warn("hello3")
}
func TestLoggerIsEnabled(t *testing.T) {
SetLevel(WarnLevel)
l := GetLogger()
if l.IsDebugEnabled() {
l.Debug("debug....")
}
if l.IsInfoEnabled() {
l.Info("info....")
}
}
// BenchmarkLoggerIsEnabled-12 85532004 14.14 ns/op
func BenchmarkLoggerIsEnabled(b *testing.B) {
SetLevel(WarnLevel)
SetLoggerLevel("abc", InfoLevel)
SetLoggerLevel("xyz", TraceLevel)
l := NewLogger("abc")
for i := 0; i < b.N; i++ {
_ = l.IsInfoEnabled()
}
}