-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzzap_test.go
66 lines (52 loc) · 1.39 KB
/
zzap_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
package zzap_test
import (
"encoding/json"
"strconv"
"testing"
"github.com/bool64/logz"
"github.com/bool64/logz/zzap"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
func TestNewOption(t *testing.T) {
zc := zap.NewProductionConfig()
zz, lo := zzap.NewOption(logz.Config{
MaxCardinality: 5,
MaxSamples: 10,
})
zc.OutputPaths = nil
l, err := zc.Build(zz)
require.NoError(t, err)
l.With(zap.String("k", "v")).Sugar().Warnw("message", "index", 1)
entries := lo[zap.WarnLevel+1].GetEntriesWithSamples()
assert.Equal(t, uint64(1), entries[0].Count)
assert.Equal(t, "message", entries[0].Message)
j, err := json.Marshal(entries[0].Samples[0])
require.NoError(t, err)
assert.Contains(t, string(j), `"msg":"message","index":1,"k":"v"`)
}
func BenchmarkLogzSugarWarn(b *testing.B) {
b.ReportAllocs()
zc := zap.NewProductionConfig()
zz, _ := zzap.NewOption(logz.Config{
MaxCardinality: 5,
MaxSamples: 10,
})
zc.OutputPaths = nil
l, err := zc.Build(zz)
require.NoError(b, err)
for i := 0; i < b.N; i++ {
l.Sugar().Warnw("message"+strconv.Itoa(i%100), "index", i)
}
}
func BenchmarkRawSugarWarn(b *testing.B) {
b.ReportAllocs()
zc := zap.NewProductionConfig()
zc.OutputPaths = nil
l, err := zc.Build()
require.NoError(b, err)
for i := 0; i < b.N; i++ {
l.Sugar().Warnw("message"+strconv.Itoa(i%100), "index", i)
}
}