1 Star 0 Fork 0

Wsage/go-framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
log.go 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
王少奇 提交于 2021-08-11 15:12 . 优化 response
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...))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/scottq/go-framework.git
git@gitee.com:scottq/go-framework.git
scottq
go-framework
go-framework
v1.1.8

搜索帮助