Codebase list golang-github-go-kit-kit / a7d50df
Use NopLogger in tests. Chris Hines 8 years ago
2 changed file(s) with 6 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
66
77 "github.com/go-kit/kit/log"
88 )
9
10 var discard = log.Logger(log.LoggerFunc(func(...interface{}) error { return nil }))
119
1210 func TestContext(t *testing.T) {
1311 t.Parallel()
110108 }
111109
112110 func BenchmarkDiscard(b *testing.B) {
113 logger := discard
111 logger := log.NewNopLogger()
114112 b.ReportAllocs()
115113 b.ResetTimer()
116114 for i := 0; i < b.N; i++ {
119117 }
120118
121119 func BenchmarkOneWith(b *testing.B) {
122 logger := discard
120 logger := log.NewNopLogger()
123121 lc := log.NewContext(logger).With("k", "v")
124122 b.ReportAllocs()
125123 b.ResetTimer()
129127 }
130128
131129 func BenchmarkTwoWith(b *testing.B) {
132 logger := discard
130 logger := log.NewNopLogger()
133131 lc := log.NewContext(logger).With("k", "v")
134132 for i := 1; i < 2; i++ {
135133 lc = lc.With("k", "v")
142140 }
143141
144142 func BenchmarkTenWith(b *testing.B) {
145 logger := discard
143 logger := log.NewNopLogger()
146144 lc := log.NewContext(logger).With("k", "v")
147145 for i := 1; i < 10; i++ {
148146 lc = lc.With("k", "v")
8888 }
8989
9090 func BenchmarkValueBindingTimestamp(b *testing.B) {
91 logger := discard
91 logger := log.NewNopLogger()
9292 lc := log.NewContext(logger).With("ts", log.DefaultTimestamp)
9393 b.ReportAllocs()
9494 b.ResetTimer()
9898 }
9999
100100 func BenchmarkValueBindingCaller(b *testing.B) {
101 logger := discard
101 logger := log.NewNopLogger()
102102 lc := log.NewContext(logger).With("caller", log.DefaultCaller)
103103 b.ReportAllocs()
104104 b.ResetTimer()