-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrlog_test.go
More file actions
72 lines (60 loc) · 1.6 KB
/
rlog_test.go
File metadata and controls
72 lines (60 loc) · 1.6 KB
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
package qlog
import "testing"
func TestGetRLog(t *testing.T) {
tests := []struct {
name string
moduleName string
traceID string
message string
}{
{
name: "基础日志测试",
moduleName: "test_module",
message: "test message",
},
{
name: "带追踪ID的日志测试",
moduleName: "test_module",
traceID: "trace_123",
message: "traced message",
},
{
name: "空模块名测试",
moduleName: "",
message: "empty module message",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// 获取日志实例
rlog := GetRLog(tt.moduleName)
if rlog == nil {
t.Fatal("GetRLog返回了nil")
}
// 测试所有日志级别的基本方法
rlog.Debug(tt.message)
rlog.Debugf("%s - debug formatted", tt.message)
rlog.Info(tt.message)
rlog.Infof("%s - info formatted", tt.message)
rlog.Warn(tt.message)
rlog.Warnf("%s - warn formatted", tt.message)
rlog.Error(tt.message)
rlog.Errorf("%s - error formatted", tt.message)
// 测试带TraceID的各个级别日志
if tt.traceID != "" {
tracedLogger := rlog.WithTraceId(tt.traceID)
if tracedLogger == nil {
t.Error("WithTraceId返回了nil")
}
tracedLogger.Debug(tt.message)
tracedLogger.Debugf("%s - traced debug", tt.message)
tracedLogger.Info(tt.message)
tracedLogger.Infof("%s - traced info", tt.message)
tracedLogger.Warn(tt.message)
tracedLogger.Warnf("%s - traced warn", tt.message)
tracedLogger.Error(tt.message)
tracedLogger.Errorf("%s - traced error", tt.message)
}
})
}
}