-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler_test.go
47 lines (41 loc) · 985 Bytes
/
handler_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 glo
import (
"bytes"
"testing"
"time"
)
func TestHandler(t *testing.T) {
formatter := NewFormatter("[{L}] {M}")
expect := formatter.Format(time.Now(), Info, "x") + "\n"
bfr := bytes.NewBufferString("")
hndl := NewHandler(bfr).SetFormatter(formatter)
// Simple write
hndl.Log(Info, "x")
if rs := bfr.String(); rs != expect {
t.Error("log was not written")
}
// Validate Level
bfr.Truncate(0)
hndl.PushFilter(NewFilterLevel(Emergency))
hndl.Log(Debug, "x")
hndl.Log(Info, "x")
hndl.Log(Notice, "x")
hndl.Log(Warning, "x")
hndl.Log(Error, "x")
hndl.Log(Critical, "x")
hndl.Log(Alert, "x")
if rs := bfr.String(); rs != "" {
t.Error("severity was not ignored")
}
hndl.Log(Emergency, "x")
if rs := bfr.String(); rs != "[EMERGENCY] x\n" {
t.Error("severity was ignored")
}
// Clear validators
bfr.Truncate(0)
hndl.ClearFilters()
hndl.Log(Debug, "x")
if rs := bfr.String(); rs != "[DEBUG] x\n" {
t.Error("validators were not cleared")
}
}