MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestInitLogger

Function TestInitLogger

pkg/util/log/log_test.go:13–32  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestInitLogger(t *testing.T) {
14 stderr := os.Stderr
15 r, w, err := os.Pipe()
16 require.NoError(t, err)
17 os.Stderr = w
18 defer func() { os.Stderr = stderr }()
19
20 cfg := &server.Config{}
21 require.NoError(t, cfg.LogLevel.Set("debug"))
22 InitLogger(cfg)
23
24 level.Debug(Logger).Log("hello", "world")
25 cfg.Log.Debugf("%s %s", "hello", "world")
26
27 require.NoError(t, w.Close())
28 logs, err := io.ReadAll(r)
29 require.NoError(t, err)
30 require.Contains(t, string(logs), "caller=log_test.go:24 level=debug hello=world")
31 require.Contains(t, string(logs), "caller=log_test.go:25 level=debug msg=\"hello world\"")
32}
33
34func BenchmarkDisallowedLogLevels(b *testing.B) {
35 cfg := &server.Config{}

Callers

nothing calls this directly

Calls 4

InitLoggerFunction · 0.85
SetMethod · 0.65
CloseMethod · 0.65
LogMethod · 0.45

Tested by

no test coverage detected