-
Notifications
You must be signed in to change notification settings - Fork 0
/
logex_test.go
62 lines (50 loc) · 1022 Bytes
/
logex_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
54
55
56
57
58
59
60
61
62
package log
import (
"bytes"
"io"
"strings"
"testing"
)
func (s *S) hello() {
s.Warn("warn in hello")
}
func log(buf io.Writer, s string) {
Logger{Logger: NewGoLog(buf)}.Output(2, s)
}
func test(buf io.Writer) {
log(buf, "aa")
Info("b")
NewLoggerEx(buf).Info("c")
Error("ec")
s.hello()
Struct(&s, 1, "", false)
}
// -------------------------------------------------------------------
type S struct {
Logger
}
var s = S{}
func TestLogex(t *testing.T) {
buf := bytes.NewBuffer(nil)
logger := NewLoggerEx(buf)
logger.depth = 1
goLogStd = logger.Logger
SetStd(logger)
test(buf)
ret := buf.String()
println("--------\n", ret)
except := []string{
".test:logex_test.go:19]aa",
".test:logex_test.go:20][INFO] b",
".test:logex_test.go:21][INFO] c",
".test:logex_test.go:22][ERROR] ec",
".(*S).hello:logex_test.go:11][WARN] warn in hello",
}
for _, e := range except {
idx := strings.Index(ret, e)
if idx < 0 {
t.Fatal("except", e, "not found")
}
ret = ret[idx+len(e):]
}
}