MCPcopy
hub / github.com/sirupsen/logrus / TestDifferentLevelsGoToDifferentWriters

Function TestDifferentLevelsGoToDifferentWriters

hooks/writer/writer_test.go:12–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestDifferentLevelsGoToDifferentWriters(t *testing.T) {
13 var a, b bytes.Buffer
14
15 log.SetFormatter(&log.TextFormatter{
16 DisableTimestamp: true,
17 DisableColors: true,
18 })
19 log.SetOutput(io.Discard) // Send all logs to nowhere by default
20
21 log.AddHook(&Hook{
22 Writer: &a,
23 LogLevels: []log.Level{
24 log.WarnLevel,
25 },
26 })
27 log.AddHook(&Hook{ // Send info and debug logs to stdout
28 Writer: &b,
29 LogLevels: []log.Level{
30 log.InfoLevel,
31 },
32 })
33 log.Warn("send to a")
34 log.Info("send to b")
35
36 assert.Equal(t, "level=warning msg=\"send to a\"\n", a.String())
37 assert.Equal(t, "level=info msg=\"send to b\"\n", b.String())
38}

Callers

nothing calls this directly

Calls 6

SetFormatterMethod · 0.80
SetOutputMethod · 0.80
AddHookMethod · 0.80
WarnMethod · 0.65
InfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected