log_test.go 2.18 KB
Newer Older
“李磊”'s avatar
“李磊” committed
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
63
64
65
66
67
68
69
70
71
72
73
74
75
package l

import (
	"fmt"
	"testing"
)

func TestLog(t *testing.T) {
	EnableDebug()
	Debug("Debug", "log")
	Debugf("Debugf %s", "log")
	Debugj("Debugj", map[string]interface{}{"name": "zhangsan", "age": 10})
	Debugs("Debugs")
	Info("Info", "log")
	Infof("Infof %s", "log")
	Warn("Warn", "log")
	Warnf("Warnf %s", "log")
	// 正常err测试
	Error()
	Errorf()
	WrapError()
	WrapErrorf()
	fmt.Println(GetError())
	fmt.Println(GetErrorf())
	Error("Error", "log")
	Errorf("Errorf %s", "log")
	fmt.Println(GetError("Error", "log"))
	fmt.Println(GetErrorf("Errorf %s", "log"))
	err0 := WrapError("Error", "log")
	fmt.Println(err0)
	err1 := WrapErrorf("Errorf %s", "log")
	fmt.Println(err1)
	// 测试只传入code
	Error(BackendModNotRunning)
	Errorf(BackendModNotRunning)
	fmt.Println(GetError(BackendModNotRunning))
	fmt.Println(GetErrorf(BackendModNotRunning))
	err2 := WrapError(BackendModNotRunning)
	fmt.Println(err2)
	err3 := WrapErrorf(BackendModNotRunning)
	fmt.Println(err3)
	// 测试只传入code及一个参数
	Error(BackendModNotRunning, "test one code one error")
	Errorf(BackendModNotRunning, "test one code one error")
	Errorf(BackendModNotRunning, "error %s", "log")
	fmt.Println(GetError(BackendModNotRunning, "test one code one error"))
	fmt.Println(GetErrorf(BackendModNotRunning, "test one code one error"))
	fmt.Println(GetErrorf(BackendModNotRunning, "error %s", "log"))
	err4 := WrapError(BackendModNotRunning, "test one code one error")
	fmt.Println(err4)
	err5 := WrapErrorf(BackendModNotRunning, "test one code one error")
	fmt.Println(err5)
	err6 := WrapErrorf(BackendModNotRunning, "error %s", "log")
	fmt.Println(err6)
	// 测试获取errcode
	Error(err4)
	Errorf(err4)
	fmt.Println(GetError(err4))
	fmt.Println(GetErrorf(err4))
	err7 := WrapError(err4)
	fmt.Println(err7)
	err8 := WrapErrorf(err4)
	fmt.Println(err8)
	// Fatal("Fatal", "log")
	// Fatalf("Fatalf %s", "log")
}

func TestStdoutBytesAndStdoutLimit(t *testing.T) {
	t.Logf("before write bytes: %d", GetStdoutBytes())
	SetStdoutLimit(10)
	t.Logf("stdout limit: %d", GetStdoutLimit())
	Info("hello")
	Info("not print")
	t.Logf("after write bytes: %d", GetStdoutBytes())
}