-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_test.go
47 lines (40 loc) · 1.22 KB
/
log_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package zlog
import (
"bytes"
"strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestLogger(t *testing.T) {
Convey("With a logger", t, func() {
l := New("test_logger")
Convey("I should be able to get name and level", func() {
So(l.Name(), ShouldEqual, "test_logger")
So(l.LogLevel(), ShouldEqual, Debug)
So(l.Test(Debug), ShouldBeTrue)
})
Convey("I should be able to log a string with message", func() {
b := &bytes.Buffer{}
bl := l.Stream(b)
bl.Info().Str("hello", "world").Msg("Test")
So(strings.TrimSpace(b.String()), ShouldEqual, `{"level":"info","name":"test_logger","hello":"world","message":"Test"}`)
})
Convey("Disable Info log level", func() {
wl := l.Level(Warn)
So(wl.Info().Enabled(), ShouldBeFalse)
So(wl.Warn().Enabled(), ShouldBeTrue)
So(wl.Error().Enabled(), ShouldBeTrue)
})
Convey("Fatal and panic events must be non-nil", func() {
So(l.Fatal(), ShouldNotBeNil)
So(l.Panic(), ShouldNotBeNil)
})
Convey("Context based timestamp must be in output", func() {
b := &bytes.Buffer{}
bl := l.Stream(b)
cl := bl.With().Timestamp().Logger()
cl.Info().Msg("")
So(strings.TrimSpace(b.String()), ShouldContainSubstring, "time")
})
})
}