代码拉取完成,页面将自动刷新
// Package logx
// Date: 2023/4/10 17:23
// Author: Amu
// Description:
package logx
import (
"time"
"go.uber.org/zap/zapcore"
)
func getEncoder(config *Config) zapcore.Encoder {
if config.LogFormat == "text" {
return zapcore.NewConsoleEncoder(zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
FunctionKey: zapcore.OmitKey,
MessageKey: "message",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: cEncodeLevel,
EncodeTime: cEncodeTime,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: cEncodeCaller,
ConsoleSeparator: " || ",
})
} else {
return zapcore.NewJSONEncoder(zapcore.EncoderConfig{
// 下面以 Key 结尾的参数表示,Json格式日志中的 key
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
FunctionKey: zapcore.OmitKey,
MessageKey: "message",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format(timeFormat))
},
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
})
}
}
func cEncodeLevel(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(level.CapitalString())
}
func cEncodeTime(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format(timeFormat))
}
func cEncodeCaller(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(caller.TrimmedPath())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。