-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (55 loc) · 1.23 KB
/
main.go
File metadata and controls
62 lines (55 loc) · 1.23 KB
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
package main
import (
"time"
"strings"
"github.com/SpringDRen/easylog"
"github.com/SpringDRen/leftTicket/lefttk"
"os"
"fmt"
)
//日志
func initLog() {
now := time.Now()
logcfg := lefttk.GetSectionCfg("conf/conf.ini", "logger")
output := easylog.OutputFile
outputstr, ok := logcfg["output"]
if ok && "ALL" == strings.ToUpper(outputstr) {
output = easylog.OutputAll
}
dir, ok := logcfg["dir"]
if !ok {
dir = "./"
}
if _, err := os.Stat(dir); os.IsNotExist(err) {
// try create dir
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
fmt.Fprintf(os.Stderr, "can't create %s dir", dir)
}
}
name, ok := logcfg["name"]
if !ok {
name = "leftticket.log"
}
level, ok := logcfg["level"]
if !ok {
level = "INFO"
}
var levelInt int
if "ERROR" == strings.ToUpper(level) {
levelInt = easylog.LevelError
} else if "DEBUG" == strings.ToUpper(level) {
levelInt = easylog.LevelDebug
} else {
levelInt = easylog.LevelInfo
}
if "DEBUG" == strings.ToUpper(level) {
easylog.Debug("output:", outputstr, output, "dir:", dir, ", name:", name, ", level:", level)
}
easylog.InitFile(output, levelInt, dir, name+"."+now.Format("2006-01-02"))
}
func main() {
initLog()
defer easylog.CloseLog()
lefttk.StartMission()
}