-
Notifications
You must be signed in to change notification settings - Fork 45
/
tsv_test.go
107 lines (96 loc) · 1.56 KB
/
tsv_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
package log
import (
"io"
"net"
"testing"
)
func TestTSVLogger(t *testing.T) {
logger := TSVLogger{}
logger.New().
Timestamp().
TimestampMS().
Caller(1).
Bool(true).
Bool(false).
BoolString(true).
BoolString(false).
Byte('m').
Float64(0.618).
Int64(123).
Uint64(456).
Float32(12.0).
Int(42).
Int32(42).
Int16(42).
Int8(42).
Uint32(42).
Uint16(42).
Uint8(42).
Bytes([]byte("\"<,\t>?'")).
Str("\"<,\t>?'").
IPAddr(net.IP{1, 11, 111, 200}).
IPAddr(net.ParseIP("2001:4860:4860::8888")).
Msg()
}
func TestTSVSeparator(t *testing.T) {
logger := TSVLogger{
Separator: '¥',
}
logger.New().Msg()
logger.New().
TimestampMS().
Bool(true).
Bool(false).
BoolString(true).
BoolString(false).
Byte('m').
Float64(0.618).
Int64(123).
Uint64(456).
Float32(12.0).
Int(42).
Int32(42).
Int16(42).
Int8(42).
Uint32(42).
Uint16(42).
Uint8(42).
Bytes([]byte("\"<,\t>?'")).
Str("\"<,\t>?'").
Msg()
}
func TestTSVDiscard(t *testing.T) {
logger := TSVLogger{
Writer: io.Discard,
}
logger.New().
TimestampMS().
Bool(true).
Bool(false).
BoolString(true).
BoolString(false).
Float64(0.618).
Int64(123).
Uint64(456).
Float32(12.0).
Int(42).
Int32(42).
Int16(42).
Int8(42).
Uint32(42).
Uint16(42).
Uint8(42).
Bytes([]byte("\"<,\t>?'")).
Str("\"<,\t>?'").
Msg()
}
func BenchmarkTSVLogger(b *testing.B) {
logger := TSVLogger{
Writer: io.Discard,
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.New().TimestampMS().Str("a tsv message").Msg()
}
}