1 Star 0 Fork 0

water/gobase

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
go_logger.go 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
package golog
import (
"context"
"fmt"
"gitee.com/leijmdas/gobase/goconfig/common/golog/goutils"
"github.com/sirupsen/logrus"
"path/filepath"
"runtime"
)
var logger = logrus.New()
func init() {
logger.SetReportCaller(true)
logger.Formatter = &logrus.JSONFormatter{
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
// 简化文件名
filename := filepath.Base(f.File)
return "", fmt.Sprintf("%s:%d", filename, f.Line)
},
}
}
func LogInfo(args ...interface{}) {
// 使用标准logrus方法
logger.Info(args...)
}
func Info(v ...interface{}) {
goutils.FindBeanGoLog().Info(context.Background(), v...)
logrus.Info(v...)
}
func Println(v ...interface{}) {
goutils.FindBeanGoLog().Info(context.Background(), v...)
logrus.Info(v...)
}
func Debug(v ...interface{}) {
goutils.Debug(v...)
}
func Warn(v ...interface{}) {
goutils.FindBeanGoLog().Warning(context.Background(), v...)
logrus.Info(v...)
}
func Error(v ...interface{}) {
goutils.Error(v...)
}
func Stat(v ...interface{}) {
goutils.Stat(v...)
}
func StatInfo(v ...interface{}) {
goutils.Stat(v...)
logrus.Info(v)
}
func InitLogrus() {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetReportCaller(true)
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
EnvironmentOverrideColors: true,
TimestampFormat: "2006-01-12 15:04:05", //时间格式
FullTimestamp: true,
DisableLevelTruncation: true,
})
}
func InfoDb(v ...interface{}) {
goutils.InfoDb(v...)
}
func ErrorDb(v ...interface{}) {
goutils.ErrorDb(v...)
}
func InfoEs(v ...interface{}) {
goutils.InfoEs(v...)
}
func ErrorEs(v ...interface{}) {
goutils.Error(v...)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/leijmdas/gobase.git
git@gitee.com:leijmdas/gobase.git
leijmdas
gobase
gobase
e3601d1820c0

搜索帮助