hooks: add a null logger for the lower-case import

This commit is contained in:
Simon Eskildsen
2017-05-12 14:51:38 -04:00
parent 79043dd8d5
commit a06c2db727
2 changed files with 106 additions and 7 deletions
+14 -7
View File
@@ -434,15 +434,22 @@ Logrus has a built in facility for asserting the presence of log messages. This
* a test logger (`test.NewNullLogger`) that just records log messages (and does not output any):
```go
logger, hook := NewNullLogger()
logger.Error("Hello error")
import (
"testing"
"github.com/sirupsen/logrus/hooks/null"
)
assert.Equal(1, len(hook.Entries))
assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
assert.Equal("Hello error", hook.LastEntry().Message)
func TestSomething(t *testing.T) {
logger, hook := null.NewNullLogger()
logger.Error("Hello error")
hook.Reset()
assert.Nil(hook.LastEntry())
assert.Equal(1, len(hook.Entries))
assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
assert.Equal("Hello error", hook.LastEntry().Message)
hook.Reset()
assert.Nil(hook.LastEntry())
}
```
#### Fatal handlers