-
Notifications
You must be signed in to change notification settings - Fork 2
/
Logconf.go
73 lines (65 loc) · 1.9 KB
/
Logconf.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
package Logger
import (
"fmt"
)
//LogLevel 日志等级
type LogLevel uint
//日志等级之间都有10段预留
//为了日后实际开发时,可能出现的自定义日志等级
const (
LogLevelmainlevel LogLevel = 0
LogLeveldebuglevel LogLevel = 10
LogLevelinfolevel LogLevel = 20
LogLevelstatuslevel LogLevel = 30
LogLevelerrorlevel LogLevel = 40
LogLevelfatallevel LogLevel = 50
)
//日志模式
type LogMode uint
const (
LogModeDef LogMode = 0 //默认
LogModeMain LogMode = 1 //只输出main文件
LogModeFmt LogMode = 2 //只出输cmd
)
const (
pmainlevel = "[main ]"
pdebuglevel = "[debug ]"
pinfolevel = "[info ]"
pstatuslevel = "[status ]"
perrorlevel = "[error ]"
pfatallevel = "[fatal ]"
)
//GetFileNameByLogLevel 按日志等级生成前缀
func GetFileNameByLogLevel(lv LogLevel) (result string) {
if lv == LogLevelmainlevel {
result = fmt.Sprintf("main_%d", lv)
} else if lv <= LogLeveldebuglevel {
result = fmt.Sprintf("debug_%d", lv)
} else if lv <= LogLevelinfolevel {
result = fmt.Sprintf("info_%d", lv)
} else if lv <= LogLevelstatuslevel {
result = fmt.Sprintf("status_%d", lv)
} else if lv <= LogLevelerrorlevel {
result = fmt.Sprintf("error_%d", lv)
} else if lv <= LogLevelfatallevel {
result = fmt.Sprintf("fatal_%d", lv)
}
return result
}
//GetLogNameByLogLevel 按日志等级生成日志等级的名字
func GetLogNameByLogLevel(lv LogLevel) (result string) {
if lv == LogLevelmainlevel {
result = fmt.Sprintf("[main_%d]", lv)
} else if lv <= LogLeveldebuglevel {
result = fmt.Sprintf("[debug_%d]", lv)
} else if lv <= LogLevelinfolevel {
result = fmt.Sprintf("[info_%d]", lv)
} else if lv <= LogLevelstatuslevel {
result = fmt.Sprintf("[status_%d]", lv)
} else if lv <= LogLevelerrorlevel {
result = fmt.Sprintf("[error_%d]", lv)
} else if lv <= LogLevelfatallevel {
result = fmt.Sprintf("[fatal_%d]", lv)
}
return result
}