1 Star 0 Fork 0

ggymm/desktop-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
logger.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
ggymm 提交于 2021-05-10 20:31 . Initial commit
package main
import (
"os"
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
)
var Logger *zap.SugaredLogger
func init() {
w := zapcore.AddSync(&lumberjack.Logger{
Filename: "log/desktop-chat.log",
MaxSize: 256,
Compress: true,
})
atomicLevel := zap.NewAtomicLevel()
atomicLevel.SetLevel(zap.DebugLevel)
core := zapcore.NewCore(
zapcore.NewConsoleEncoder(NewEncoderConfig()),
zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), w),
atomicLevel,
)
Logger = zap.New(core).Sugar()
defer func() {
_ = Logger.Sync()
}()
}
func NewEncoderConfig() zapcore.EncoderConfig {
return zapcore.EncoderConfig{
// Keys can be anything except the empty string.
TimeKey: "T",
LevelKey: "L",
NameKey: "N",
CallerKey: "C",
MessageKey: "M",
StacktraceKey: "S",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.CapitalLevelEncoder,
EncodeTime: TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
}
}
func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format("2006-01-02 15:04:05"))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/1967988842/desktop-go.git
git@gitee.com:1967988842/desktop-go.git
1967988842
desktop-go
desktop-go
master

搜索帮助