1 Star 0 Fork 20

少林码僧 / gobatis

forked from aurora-engine / gobatis 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
log.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
aurora.io 提交于 2022-12-06 16:34 . 更新 gobatis 报名
package gobatis
import (
"bytes"
"fmt"
"github.com/sirupsen/logrus"
"os"
"sync"
)
var logs *logrus.Logger
// Log 自定义Log需要实现的借口
type Log interface {
Info(...interface{})
Error(...interface{})
Debug(...interface{})
Panic(...interface{})
Warn(...interface{})
}
func init() {
logs = logrus.New()
f := &Formatter{ProjectName: "SGO"}
f.Buf = &sync.Pool{New: func() any {
return new(bytes.Buffer)
}}
logs.SetFormatter(f)
logs.Out = os.Stdout
}
func Level(level logrus.Level) {
logs.SetLevel(level)
}
type Formatter struct {
ProjectName string
Buf *sync.Pool
*logrus.TextFormatter
}
func Info(msg ...any) {
logs.Infoln(msg...)
}
func Debug(msg ...any) {
logs.Debugln(msg...)
}
func Error(err ...any) {
logs.Errorln(err...)
}
func Panic(v ...any) {
logs.Panicln(v...)
}
func (format *Formatter) Format(entry *logrus.Entry) ([]byte, error) {
buf := format.Buf.Get().(*bytes.Buffer)
defer format.Buf.Put(buf)
defer buf.Reset()
var f = ""
t := entry.Time.Format("2006-01-02 15:04:05")
if entry.Data != nil && len(entry.Data) > 0 {
f = fmt.Sprintf("[%s] %s [%s] [%s] -> %s\n", format.ProjectName, t, entry.Level, entry.Data["type"], entry.Message)
} else {
f = fmt.Sprintf("[%s] %s [%s] -> %s\n", format.ProjectName, t, entry.Level, entry.Message)
}
buf.WriteString(f)
return buf.Bytes(), nil
}
Go
1
https://gitee.com/phper95/gobatis.git
git@gitee.com:phper95/gobatis.git
phper95
gobatis
gobatis
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891