logger.go
1.4 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
63
64
65
66
67
68
69
70
//package constant
//var Logger log.Logger
// 日志输出
//func init() {
// Logger = logrus.NewLogrusLogger()
// Logger.SetServiceName(constant.SERVICE_NAME)
// Logger.SetLevel(constant.LOG_LEVEL)
//}
package log
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant"
"path/filepath"
"strconv"
)
var Logger *logs.BeeLogger
func init() {
Logger = NewBeegoLogger(LoggerConfig{
Filename: constant.LOG_File,
Level: constant.LOG_LEVEL,
})
}
type LoggerConfig struct {
Level string `json:"level,omitempty"`
Filename string `json:"filename,omitempty"`
MaxSize int `json:"max_size,omitempty"`
MaxBackups int `json:"max_backups,omitempty"`
MaxAge int `json:"max_age,omitempty"`
Compress bool `json:"compress,omitempty"`
}
func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger {
filename := `{"filename":"` + filepath.ToSlash(conf.Filename) + `"}`
log := logs.GetBeeLogger()
log.SetLogger(logs.AdapterFile, filename)
ilv, err := strconv.Atoi(conf.Level)
if err != nil {
ilv = logs.LevelDebug
}
log.SetLevel(ilv)
log.EnableFuncCallDepth(true)
log.SetLogFuncCallDepth(5)
log.SetPrefix(constant.LOG_PREFIX)
return log
}
func Debug(args ...interface{}) {
beego.Debug(args...)
}
func Info(args ...interface{}) {
beego.Info(args...)
}
func Warn(args ...interface{}) {
beego.Warn(args...)
}
func Error(args ...interface{}) {
beego.Error(args...)
}