-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext_formatter_test.go
48 lines (40 loc) · 1.17 KB
/
text_formatter_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
48
package golog_test
import (
"fmt"
"testing"
"github.com/chapsuk/golog"
test "github.com/smartystreets/goconvey/convey"
)
func TestTextFormatter(t *testing.T) {
test.Convey("Check text formatter", t, func() {
out := &FakeWriter{}
log := golog.NewLogger(out, &golog.TextFormatter{DateFormat: " "}, golog.Context{})
test.Convey("write with default date format", func() {
log.SetFormatter(&golog.TextFormatter{})
log.Info("info message")
test.So(out.log, test.ShouldHaveLength, 1)
})
test.Convey("write without context", func() {
log.Info("info message")
test.So(out.log, test.ShouldContain, " INFO [] info message\n")
})
test.Convey("write with context (without sort) [foo: foo, err: err, int: 1]", func() {
log.InfoCtx(golog.Context{
"foo": foo,
"err": fmt.Errorf("error"),
"int": 1,
}, "this log message")
// only check length
test.So(out.log, test.ShouldHaveLength, 1)
for _, v := range out.log {
fmt.Print(v)
}
})
test.Convey("write with trace", func() {
log.SetTraceLevel(golog.DebugLevel)
test.So(out.log, test.ShouldBeEmpty)
log.Debug("trace debug")
test.So(out.log, test.ShouldNotBeEmpty)
})
})
}