logger.go 768 字节
package log

import (
	"encoding/json"

	"github.com/astaxie/beego/logs"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
)

func init() {

	logs.SetLevel(logLevel(constant.LOG_LEVEL))
	logs.SetLogFuncCall(false)
	logs.SetLogger("file", getlogFileConfig())
	logs.Async()
	logs.Async(2 * 1e3)
}

func getlogFileConfig() string {
	m := map[string]string{
		"filename": constant.LOG_File,
	}
	s, _ := json.Marshal(m)
	return string(s)
}

//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) {
	logs.Debug("SQL PRINT : ", string(bt))
}