代码拉取完成,页面将自动刷新
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) error
Info(log string) error
Warn(log string) error
Error(log string) error
Panic(log string) error
Fatal(log string) error
Debugf(log string, params ...interface{}) error
Infof(log string, params ...interface{}) error
Warnf(log string, params ...interface{}) error
Errorf(log string, params ...interface{}) error
Panicf(log string, params ...interface{}) error
Fatalf(log string, params ...interface{}) error
}
//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
}
var err error
switch level {
case DebugLog:
err = ink.logger.Debug(msg)
case WarnLog:
err = ink.logger.Warn(msg)
case InfoLog:
err = ink.logger.Info(msg)
case ErrorLog:
err = ink.logger.Error(msg)
case FatalLog:
err = ink.logger.Fatal(msg)
case PanicLog:
err = ink.logger.Panic(msg)
}
if err != nil {
panic(err)
}
}
func (ink *InvokeLog) Debug(log string, params ...interface{}) error {
if ink.logger == nil {
return nil
}
return ink.logger.Debug(fmt.Sprintf(log, params...))
}
func (ink *InvokeLog) Info(log string, params ...interface{}) error {
if ink.logger == nil {
return nil
}
return ink.logger.Info(fmt.Sprintf(log, params...))
}
func (ink *InvokeLog) Warn(log string, params ...interface{}) error {
if ink.logger == nil {
return nil
}
return ink.logger.Warn(fmt.Sprintf(log, params...))
}
func (ink *InvokeLog) Error(log string, params ...interface{}) error {
if ink.logger == nil {
return nil
}
return ink.logger.Error(fmt.Sprintf(log, params...))
}
func (ink *InvokeLog) Panic(log string, params ...interface{}) error {
if ink.logger == nil {
return nil
}
return ink.logger.Panic(fmt.Sprintf(log, params...))
}
func (ink *InvokeLog) Fatal(log string, params ...interface{}) error {
if ink.logger == nil {
return nil
}
return ink.logger.Fatal(fmt.Sprintf(log, params...))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。