1 Star 0 Fork 0

Wheat / wlog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
formatter.go 828 Bytes
一键复制 编辑 原始数据 按行查看 历史
bandl 提交于 2022-05-15 10:52 . fix: add msg space
package wlog
import (
"fmt"
)
// 格式化编码器
type Formatter interface {
Format(entry *Entry) error
}
type TextFormatter struct {
// 忽略基本文件名输出
ignoreBasicFields bool
}
const (
formatTime = "2006-01-02 15:04:05"
)
func (t *TextFormatter) Format(entry *Entry) error {
entry.Buffer.WriteString(fmt.Sprintf("%s %s ", entry.Time.Format(formatTime), LevelNameMapping[entry.Level]))
if !t.ignoreBasicFields {
// 写入时间 level 信息
if entry.File != "" {
// 获取文件名
entry.Buffer.WriteString(fmt.Sprintf("%s:%d ", entry.File, entry.Line))
}
}
switch entry.Format {
// 无特殊输出,采用 %v
case FmtEmptySeparate:
entry.Buffer.WriteString(fmt.Sprint(entry.Args...))
default:
entry.Buffer.WriteString(fmt.Sprintf(entry.Format, entry.Args...))
}
return nil
}
1
https://gitee.com/wheat-os/wlog.git
git@gitee.com:wheat-os/wlog.git
wheat-os
wlog
wlog
master

搜索帮助