-
Notifications
You must be signed in to change notification settings - Fork 5
/
hlog_test.go
61 lines (51 loc) · 1.49 KB
/
hlog_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
package hlog
import (
"testing"
"time"
)
func TestNew(t *testing.T) {
logger, err := New(&Option{
LogPath: "./logs/hlog.log",
LogType: JSON,
LogLevel: DebugLevel,
MaxAge: 7 * 24 * time.Hour,
RotationTime: 24 * time.Hour,
JSONPrettyPrint: true,
IsEnableRecordFileInfo: true,
FileInfoField: "caller",
})
if err != nil {
t.Error(err)
return
}
logger.Debug(nil, "hello: %s", "world")
logger.Info(D{"hello": "world"}, "hello: %s", "world")
logger.Warn(D{"username": "warn"}, "hello: %s", "world")
logger.Error(D{"username": "Error"}, "hello: %s", "world")
//logger.Panic(D{"username": "Panic"}, "呵呵")
//logger.Fatal(D{"username": "Fatal"}, "呵呵")
}
func TestNewSeparate(t *testing.T) {
logger, err := NewSeparate(&Option{
LogPath: "./logs/hlog.log",
LogType: Text,
LogLevel: DebugLevel,
MaxAge: 7 * 24 * time.Hour,
RotationTime: 24 * time.Hour,
IsEnableRecordFileInfo: true,
FileInfoField: "called",
})
if err != nil {
t.Error(err)
return
}
logger.Debug(D{"hello": "world"}, "hello")
logger.Info(D{"hello": "world"}, "hello")
logger.Warn(D{"username": "warn"}, "呵呵")
logger.Error(D{"username": "Error"}, "呵呵")
//logger.Panic(D{"username": "Panic"}, "呵呵")
//logger.Fatal(D{"username": "Fatal"}, "呵呵")
}
func TestPrintf(t *testing.T) {
Print("hello %s %s", "world", "hehe")
}