...
1
16
17 package textlogger_test
18
19 import (
20 "io"
21 "testing"
22
23 "github.com/go-logr/logr"
24
25 "k8s.io/klog/v2/test"
26 "k8s.io/klog/v2/textlogger"
27 )
28
29
30 func newLogger(out io.Writer, v int, vmodule string) logr.Logger {
31 config := textlogger.NewConfig(
32 textlogger.Verbosity(v),
33 textlogger.Output(out),
34 )
35 if err := config.VModule().Set(vmodule); err != nil {
36 panic(err)
37 }
38 return textlogger.NewLogger(config)
39 }
40
41 var (
42 directConfig = test.OutputConfig{NewLogger: newLogger, SupportsVModule: true}
43 indirectConfig = test.OutputConfig{NewLogger: newLogger, AsBackend: true}
44 )
45
46 func TestTextloggerOutput(t *testing.T) {
47 test.InitKlog(t)
48 t.Run("direct", func(t *testing.T) {
49 test.Output(t, directConfig)
50 })
51 t.Run("klog-backend", func(t *testing.T) {
52 test.Output(t, indirectConfig)
53 })
54 }
55
56 func BenchmarkTextloggerOutput(b *testing.B) {
57 test.InitKlog(b)
58 test.Benchmark(b, directConfig)
59 }
60
View as plain text