-
Notifications
You must be signed in to change notification settings - Fork 1
/
tee_logger_test.go
53 lines (46 loc) · 1.6 KB
/
tee_logger_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
49
50
51
52
53
package logging
import (
"bytes"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestTeeLogger(t *testing.T) {
Convey("TeeLogger", t, func() {
buf1, buf2 := bytes.Buffer{}, bytes.Buffer{}
logger1 := NewTextLogger(&buf1, "Logger", TraceLevel)
logger2 := NewTextLogger(&buf2, "Logger", TraceLevel)
teelogger := NewTeeLogger(logger1, logger2)
compareBuffers := func(lev Level, str string) {
strbuf1 := buf1.String()
strbuf2 := buf2.String()
So(strbuf1, ShouldContainSubstring, lev.String())
So(strbuf2, ShouldContainSubstring, lev.String())
So(strbuf1, ShouldContainSubstring, str)
So(strbuf2, ShouldContainSubstring, str)
}
Convey("Writes traces to both", func() {
teelogger.Trace("Bad News Bears")
compareBuffers(TraceLevel, "Bad News Bears")
teelogger.Tracef("Bad News Bears: %s", "Ruxbin")
compareBuffers(TraceLevel, "Bad News Bears: Ruxbin")
})
Convey("Writes debugs to both", func() {
teelogger.Debug("Bad News Bears")
compareBuffers(DebugLevel, "Bad News Bears")
teelogger.Debugf("Bad News Bears: %s", "Ruxbin")
compareBuffers(DebugLevel, "Bad News Bears: Ruxbin")
})
Convey("Writes infos to both", func() {
teelogger.Info("Bad News Bears")
compareBuffers(InfoLevel, "Bad News Bears")
teelogger.Infof("Bad News Bears: %s", "Ruxbin")
compareBuffers(InfoLevel, "Bad News Bears: Ruxbin")
})
Convey("Writes errors to both", func() {
teelogger.Error("Bad News Bears")
compareBuffers(ErrorLevel, "Bad News Bears")
teelogger.Errorf("Bad News Bears: %s", "Ruxbin")
compareBuffers(ErrorLevel, "Bad News Bears: Ruxbin")
})
})
}