-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
44 lines (38 loc) · 1004 Bytes
/
util.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
package log
import (
"flag"
)
var (
crashLog = flag.String("log-crash", "./crash.log", "The crash log file.")
logFile = flag.String("log-file", "", "The external log file. Default log to console.")
logLevel = flag.String("log-level", "info", "The log level, default is info")
logRotateBy = flag.String("log-rotate-by", "day", "The log rotate by [day|hour], default is day")
logCount = flag.Int("log-count", 10, "Count of log files, default is 10")
logHigh = flag.Bool("log-high", false, "The log highlighting")
)
// Cfg is the log cfg
type Cfg struct {
LogLevel string
LogFile string
}
// InitLog init log
func InitLog() {
if !flag.Parsed() {
flag.Parse()
}
SetLogCount(*logCount)
SetHighlighting(*logHigh)
SetLevelByString(*logLevel)
if "" != *logFile {
if *logRotateBy == "hour" {
SetRotateByHour()
} else {
SetRotateByDay()
}
SetOutputByName(*logFile)
CrashLog(*crashLog)
}
if !DebugEnabled() {
SetFlags(Ldate | Ltime | Lmicroseconds)
}
}