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

Function TestAllHooks

hooks/test/test_test.go:13–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestAllHooks(t *testing.T) {
14 assert := assert.New(t)
15
16 logger, hook := NewNullLogger()
17 assert.Nil(hook.LastEntry())
18 assert.Equal(0, len(hook.Entries))
19
20 logger.Error("Hello error")
21 assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
22 assert.Equal("Hello error", hook.LastEntry().Message)
23 assert.Equal(1, len(hook.Entries))
24
25 logger.Warn("Hello warning")
26 assert.Equal(logrus.WarnLevel, hook.LastEntry().Level)
27 assert.Equal("Hello warning", hook.LastEntry().Message)
28 assert.Equal(2, len(hook.Entries))
29
30 hook.Reset()
31 assert.Nil(hook.LastEntry())
32 assert.Equal(0, len(hook.Entries))
33
34 hook = NewGlobal()
35
36 logrus.Error("Hello error")
37 assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
38 assert.Equal("Hello error", hook.LastEntry().Message)
39 assert.Equal(1, len(hook.Entries))
40}
41
42func TestLoggingWithHooksRace(t *testing.T) {
43

Callers

nothing calls this directly

Calls 7

ErrorFunction · 0.92
NewNullLoggerFunction · 0.85
NewGlobalFunction · 0.85
LastEntryMethod · 0.80
ResetMethod · 0.80
ErrorMethod · 0.65
WarnMethod · 0.65

Tested by

no test coverage detected