-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlog.go
More file actions
38 lines (31 loc) · 691 Bytes
/
log.go
File metadata and controls
38 lines (31 loc) · 691 Bytes
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
package main
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/logs"
)
func convertLogLevel(level string) int {
switch level {
case "debug":
return logs.LevelDebug
case "info":
return logs.LevelInfo
case "warn":
return logs.LevelWarn
case "trace":
return logs.LevelTrace
}
return logs.LevelDebug
}
func InitLogger() (err error) {
config := make(map[string]interface{})
config["filename"] = AppConfig.LogPath
config["level"] = convertLogLevel(AppConfig.LogLevel)
configStr, err := json.Marshal(config)
if err != nil {
fmt.Println("initLogger failed, marshal failed, err:", err)
return
}
logs.SetLogger(logs.AdapterFile, string(configStr))
return
}