From 7c6a252ab3f7d9aeb743f9fa8d0cc8c7402f984d Mon Sep 17 00:00:00 2001 From: sbwml Date: Wed, 20 Sep 2023 20:52:27 +0800 Subject: [PATCH] format logtime --- mlog/logger.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mlog/logger.go b/mlog/logger.go index c8b08a9..b44c88d 100644 --- a/mlog/logger.go +++ b/mlog/logger.go @@ -1,17 +1,28 @@ package mlog -import "go.uber.org/zap" +import ( + "time" + + "go.uber.org/zap" + "go.uber.org/zap/zapcore" +) var logger = mustInitLogger() func mustInitLogger() *zap.Logger { - l, err := zap.NewDevelopment(zap.WithCaller(false)) + config := zap.NewDevelopmentConfig() + config.EncoderConfig.EncodeTime = customTimeEncoder + l, err := config.Build(zap.WithCaller(false)) if err != nil { panic("failed to init mlog:" + err.Error()) } return l } +func customTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) { + enc.AppendString(t.Format("2006-01-02 15:04:05")) +} + func L() *zap.Logger { return logger } -- 2.34.8