-
Notifications
You must be signed in to change notification settings - Fork 49
/
log_level_test.go
53 lines (51 loc) · 1019 Bytes
/
log_level_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 log
import (
"encoding/json"
"io"
"testing"
)
func TestLogLevel(t *testing.T) {
const subsystem = "log-level-test"
logger := Logger(subsystem)
reader := NewPipeReader()
done := make(chan struct{})
go func() {
defer close(done)
decoder := json.NewDecoder(reader)
for {
var entry struct {
Message string `json:"msg"`
Caller string `json:"caller"`
}
err := decoder.Decode(&entry)
switch err {
default:
t.Error(err)
return
case io.EOF:
return
case nil:
}
if entry.Message != "bar" {
t.Errorf("unexpected message: %s", entry.Message)
}
if entry.Caller == "" {
t.Errorf("no caller in log entry")
}
}
}()
logger.Debugw("foo")
if err := SetLogLevel(subsystem, "debug"); err != nil {
t.Error(err)
}
logger.Debugw("bar")
SetAllLoggers(LevelInfo)
logger.Debugw("baz")
// ignore the error because
// https://github.com/uber-go/zap/issues/880
_ = logger.Sync()
if err := reader.Close(); err != nil {
t.Error(err)
}
<-done
}