审查视图

pkg/log/logger.go 768 字节
tangxvhui authored
1 2 3
package log

import (
tangxvhui authored
4 5
	"encoding/json"
tangxvhui authored
6 7 8 9 10
	"github.com/astaxie/beego/logs"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
)

func init() {
tangxvhui authored
11
tangxvhui authored
12
	logs.SetLevel(logLevel(constant.LOG_LEVEL))
tangxvhui authored
13
	logs.SetLogFuncCall(false)
tangxvhui authored
14
	logs.SetLogger("file", getlogFileConfig())
tangxvhui authored
15 16
	logs.Async()
	logs.Async(2 * 1e3)
tangxvhui authored
17 18
}
tangxvhui authored
19 20 21 22 23 24 25 26
func getlogFileConfig() string {
	m := map[string]string{
		"filename": constant.LOG_File,
	}
	s, _ := json.Marshal(m)
	return string(s)
}
tangxvhui authored
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
//LogLevel ...
func logLevel(s string) (i int) {
	switch s {
	case "info":
		i = logs.LevelInfo
	case "debug":
		i = logs.LevelDebug
	case "warning":
		i = logs.LevelWarning
	case "error":
		i = logs.LevelError
	default:
		i = logs.LevelDebug
	}
	return
}

func PrintSql(bt []byte) {
tangxvhui authored
45
	logs.Debug("SQL PRINT : ", string(bt))
tangxvhui authored
46
}