-
Notifications
You must be signed in to change notification settings - Fork 1
/
log_level.go
84 lines (74 loc) · 1.77 KB
/
log_level.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
package log
// Level 表示日志级别
type Level uint8
const (
// TraceLevel 底层跟踪日志
TraceLevel Level = iota
// DebugLevel 调试级别日志
DebugLevel
// InfoLevel 信息级别日志
InfoLevel
// WarnLevel 警告级别日志
WarnLevel
// ErrorLevel 错误级别日志
ErrorLevel
// FatalLevel 崩溃日志
FatalLevel
// NoLog 不输出任何日志
NoLog
)
func (l Level) String() string {
if l >= NoLog {
l = NoLog
}
return internal.levelToString[l]
}
// SetLevel 设置日志级别
func SetLevel(file, console Level) {
if file >= NoLog {
file = NoLog + 1
}
if console >= NoLog {
console = NoLog + 1
}
internal.level.normal.file = file
internal.level.normal.console = console
}
// SetFileLevel 设置日志文件级别
func SetFileLevel(lv Level) {
console := internal.level.normal.console
SetLevel(lv, console)
}
// SetConsoleLevel 设置 console 日志级别
func SetConsoleLevel(lv Level) {
file := internal.level.normal.file
SetLevel(file, lv)
}
// SetDyeingLevel 设置染色日志级别
func SetDyeingLevel(file, console Level) {
if file >= NoLog {
file = NoLog + 1
}
if console >= NoLog {
console = NoLog + 1
}
internal.level.dyeing.file = file
internal.level.dyeing.console = console
}
// SetFileDyeingLevel 设置日志文件染色级别
func SetFileDyeingLevel(lv Level) {
console := internal.level.dyeing.console
SetDyeingLevel(lv, console)
}
// SetConsoleDyeingLevel 设置 console 日志染色级别
func SetConsoleDyeingLevel(lv Level) {
file := internal.level.dyeing.file
SetDyeingLevel(file, lv)
}
// SetSkipCaller 当外部封装本 logger 时, 可以设置该值, 那么 logger 在输出调用信息的时候
// 可以跳过指定的层数。
func SetSkipCaller(skip int) {
if skip >= 0 {
internal.caller.skip = skip
}
}