-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_test.go
95 lines (83 loc) · 2.59 KB
/
logger_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package glog
import (
"fmt"
"runtime"
"testing"
"time"
"sync"
)
func TestLogger(t *testing.T) {
//t.Errorf("print some thing")
// test Set value function.
vt := 1000
// log file abs path and relative path. can both set them.
Set("path", "/tmp/glog", "mylog")
// log file prefix name
Set("name", "kawayi")
Set("debug", false)
// add format time string to each line of log. false: hidden, true:show
// Set("show_time", false)
// every new log file top content. ofcause it could be empty.
Set("head", "auth@kawayi\nBbegin a new log every day\n")
fmt.Println("DIR LOG -------------------:", log_mgr.log_file.fullpath(), log_mgr.log_file.dir_log)
// test stack
//var tmp_buf = stack(10000)
//fmt.Println(string(tmp_buf))
for i := 0; i < 4; i++ {
_, file, line, ok := runtime.Caller(i)
fmt.Println("RUN FILE", file, ":", line, ok)
}
fmt.Println("rotate_size:", log_mgr.log_file.rotate_size, "same_date:", log_mgr.log_file.checkRotate(time.Now()), "modify time:", getFileModifyTime(log_mgr.log_file.fullname(zero_time)) )
wg := sync.WaitGroup{}
wg.Add(2)
go concurrencyLog(vt, &wg)
go concurrencyLog(vt, &wg)
wg.Wait()
// 为了校验 删除过期日志
time.Sleep(time.Second * 5)
}
func TestLetterCode(t *testing.T) {
Set("path", "/tmp/glog", "mylog")
Set("name", "kawayi")
Set("head", "auth@kawayi\nBbegin a new log every day\n")
Warnning("先弄点中文出来 log!")
wg := sync.WaitGroup{}
abssend := func() {
for i := 0; i < 1000; i++ {
Info("Oh my god. you are so clever")
//Error("================an Error log!")
Warnning("这是要追加在末尾的话 log!")
Error("================an Error log!")
}
wg.Done()
}
wg.Add(1)
go abssend()
wg.Add(1)
go abssend()
wg.Wait()
}
// =================================function===============================
func concurrencyLog(send_time int, wg *sync.WaitGroup) {
t1 := time.Now()
for i := 0; i < send_time; i++ {
Debug("testing something.")
Info("Oh my god. you are so clever.")
Warnning("这是要追加在末尾的话 log!")
Error("================an Error log!")
ErrorDepth(0, "this an user defined depth error log.")
}
elaps := time.Since(t1)
fmt.Println("[PRINT][FINISH][SEND_TIME]", elaps)
Debugf("testing something.")
Infof("Oh my god. you are so clever.")
Warnningf("这是要追加在末尾的话 log!")
Errorf("================an Error log!")
Fatalf("================an Error log!")
Debugln("testing something.")
Infoln("Oh my god. you are so clever.")
Warnningln("这是要追加在末尾的话 log!")
Errorln("================an Error log!")
Fatalln("================an Error log!")
wg.Done()
}