github.com/phuslu/log@v1.0.100/tsv_test.go (about) 1 package log 2 3 import ( 4 "io" 5 "net" 6 "testing" 7 ) 8 9 func TestTSVLogger(t *testing.T) { 10 logger := TSVLogger{} 11 12 logger.New(). 13 Timestamp(). 14 TimestampMS(). 15 Caller(1). 16 Bool(true). 17 Bool(false). 18 BoolString(true). 19 BoolString(false). 20 Byte('m'). 21 Float64(0.618). 22 Int64(123). 23 Uint64(456). 24 Float32(12.0). 25 Int(42). 26 Int32(42). 27 Int16(42). 28 Int8(42). 29 Uint32(42). 30 Uint16(42). 31 Uint8(42). 32 Bytes([]byte("\"<,\t>?'")). 33 Str("\"<,\t>?'"). 34 IPAddr(net.IP{1, 11, 111, 200}). 35 IPAddr(net.ParseIP("2001:4860:4860::8888")). 36 Msg() 37 38 } 39 40 func TestTSVSeparator(t *testing.T) { 41 logger := TSVLogger{ 42 Separator: '¥', 43 } 44 45 logger.New().Msg() 46 47 logger.New(). 48 TimestampMS(). 49 Bool(true). 50 Bool(false). 51 BoolString(true). 52 BoolString(false). 53 Byte('m'). 54 Float64(0.618). 55 Int64(123). 56 Uint64(456). 57 Float32(12.0). 58 Int(42). 59 Int32(42). 60 Int16(42). 61 Int8(42). 62 Uint32(42). 63 Uint16(42). 64 Uint8(42). 65 Bytes([]byte("\"<,\t>?'")). 66 Str("\"<,\t>?'"). 67 Msg() 68 } 69 70 func TestTSVDiscard(t *testing.T) { 71 logger := TSVLogger{ 72 Writer: io.Discard, 73 } 74 75 logger.New(). 76 TimestampMS(). 77 Bool(true). 78 Bool(false). 79 BoolString(true). 80 BoolString(false). 81 Float64(0.618). 82 Int64(123). 83 Uint64(456). 84 Float32(12.0). 85 Int(42). 86 Int32(42). 87 Int16(42). 88 Int8(42). 89 Uint32(42). 90 Uint16(42). 91 Uint8(42). 92 Bytes([]byte("\"<,\t>?'")). 93 Str("\"<,\t>?'"). 94 Msg() 95 } 96 97 func BenchmarkTSVLogger(b *testing.B) { 98 logger := TSVLogger{ 99 Writer: io.Discard, 100 } 101 102 b.ReportAllocs() 103 b.ResetTimer() 104 for i := 0; i < b.N; i++ { 105 logger.New().TimestampMS().Str("a tsv message").Msg() 106 } 107 }