logger.go
1.2 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
package log
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"gitlab.fjmaimaimai.com/mmm-go/partner/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(3)
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...)
}