代码拉取完成,页面将自动刷新
package log
import (
"fmt"
)
const (
DebugLog = 1 << iota
TraceLog
InfoLog
WarnLog
ErrorLog
PanicLog
FatalLog
)
var LogLevelMap = map[int]string{
TraceLog: "Trace",
DebugLog: "Debug",
InfoLog: "Info",
WarnLog: "Warning",
ErrorLog: "Error",
FatalLog: "Fatal",
PanicLog: "Panic",
}
const DefaultLogPath = "./runtime/logs/daily.log"
type ILog interface {
Debug(log string, params ...interface{})
Info(log string, params ...interface{})
Warn(log string, params ...interface{})
Error(log string, params ...interface{})
Panic(log string, params ...interface{})
Fatal(log string, params ...interface{})
}
//fast use log
type InvokeLog struct {
logger ILog
}
func (ink *InvokeLog) AddLogger(logger ILog) {
ink.logger = logger
}
func (ink *InvokeLog) Log(level int8, msg string) {
if ink.logger == nil {
return
}
switch level {
case DebugLog:
ink.logger.Debug(msg)
case WarnLog:
ink.logger.Warn(msg)
case InfoLog:
ink.logger.Info(msg)
case ErrorLog:
ink.logger.Error(msg)
case FatalLog:
ink.logger.Fatal(msg)
case PanicLog:
ink.logger.Panic(msg)
}
}
func (ink *InvokeLog) Debug(log string, params ...interface{}) {
if ink.logger == nil {
return
}
if len(params) <= 0 {
ink.logger.Debug(log)
return
}
ink.logger.Debug(fmt.Sprintf(log, params...))
return
}
func (ink *InvokeLog) Info(log string, params ...interface{}) {
if ink.logger == nil {
return
}
if len(params) <= 0 {
ink.logger.Info(log)
return
}
ink.logger.Info(fmt.Sprintf(log, params...))
return
}
func (ink *InvokeLog) Warn(log string, params ...interface{}) {
if ink.logger == nil {
return
}
if len(params) <= 0 {
ink.logger.Warn(log)
return
}
ink.logger.Warn(fmt.Sprintf(log, params...))
return
}
func (ink *InvokeLog) Error(log string, params ...interface{}) {
if ink.logger == nil {
return
}
if len(params) <= 0 {
ink.logger.Error(log)
return
}
ink.logger.Error(fmt.Sprintf(log, params...))
return
}
func (ink *InvokeLog) Panic(log string, params ...interface{}) {
if ink.logger == nil {
return
}
if len(params) <= 0 {
ink.logger.Panic(log)
return
}
ink.logger.Panic(fmt.Sprintf(log, params...))
return
}
func (ink *InvokeLog) Fatal(log string, params ...interface{}) {
if ink.logger == nil {
return
}
if len(params) <= 0 {
ink.logger.Fatal(log)
return
}
ink.logger.Fatal(fmt.Sprintf(log, params...))
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。