-
Notifications
You must be signed in to change notification settings - Fork 1
/
init_test.go
71 lines (67 loc) · 2.18 KB
/
init_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
package k3log
import (
"fmt"
"runtime"
"testing"
"github.com/ThreeKing2018/k3log/conf"
)
func TestLogger(t *testing.T) {
SetLogger(conf.WithLogType(conf.LogJsontype), //打印json格式
conf.WithProjectName("k3日志"), //设置项目名称
conf.WithFilename("log.txt"), //设置输出文件名,或输出的路径
conf.WithLogLevel(conf.ErrorLevel), //设置日志级别,默认debug
conf.WithMaxAge(30), //日志保存天数,默认30天
conf.WithMaxSize(512), //多少M进行分隔日志,默认100M
//conf.WithStacktrace(conf.PanicLevel), //设置堆栈级别
conf.WithIsStdOut(true)) //是否同时输出控制台
defer Sync()
Debug("debug日志", 1)
Info("info日志", 2)
Warn("warn日志", 3)
Error("error日志", 4)
//Panic("panic", 5)
//Fatal("fatal", 6)
}
func BenchmarkInfo(t *testing.B) {
t.ResetTimer()
runtime.GOMAXPROCS(runtime.NumCPU())
SetLogger(conf.WithLogType(conf.LogJsontype), //打印json格式
conf.WithProjectName("k3日志"), //设置项目名称
conf.WithFilename("log.txt"), //设置输出文件名,或输出的路径
conf.WithLogLevel(conf.InfoLevel), //设置日志级别,默认debug
conf.WithMaxAge(30), //日志保存天数,默认30天
conf.WithMaxSize(10), //多少M进行分隔日志,默认100M
conf.WithStacktrace(2), //设置堆栈级别
conf.WithIsStdOut(false)) //是否同时输出控制台
defer Sync()
t.StartTimer()
for i := 0; i < t.N; i++ {
Info("测试日志", "打印结果", 100)
}
}
func TestDebug(t *testing.T) {
SetLogger(conf.WithIsStdOut(true),
conf.WithLogType(conf.LogJsontype))
Debug("ddd", 200, "aa", 2001, "bb")
}
func TestError(t *testing.T) {
Error("error", 1)
fmt.Println("继续执行")
}
func TestInfo2(t *testing.T) {
Info("aa", 11)
SetLogLevel(conf.InfoLevel)
Info("info", 100)
Warn("warn", 200)
SetLogLevel(conf.ErrorLevel)
Info("info-100", 300) //这个无法输出,因为上面设置日志级别为:error
Error("err", 400)
}
func TestDump(t *testing.T) {
type s struct {
Name string
Age int
}
SetLogger(conf.WithIsStdOut(true))
Dump("name", "dump", "s", s{Name: "k3", Age: 2})
}