From b1b7bcb660ea8c78dfabae9a7b6a79cb924a8d31 Mon Sep 17 00:00:00 2001 From: huangyitai <792037657@qq.com> Date: Thu, 9 Nov 2023 20:48:48 +0800 Subject: [PATCH] Update logger to add goid --- logger/zap.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/logger/zap.go b/logger/zap.go index fb860b3..32d45db 100644 --- a/logger/zap.go +++ b/logger/zap.go @@ -1,11 +1,14 @@ package logger import ( + "fmt" + "strings" + "time" + + "github.com/petermattis/goid" "go.uber.org/zap" "go.uber.org/zap/zapcore" "gopkg.in/natefinch/lumberjack.v2" - "strings" - "time" ) var levelStringList = []string{"debug", "info", "warn", "error", "fatal"} @@ -63,7 +66,7 @@ func InitArchiveZapLogger(config LogConfig) (zapLogger *zap.Logger) { if len(trimPath) > 40 { trimPath = trimPath[len(trimPath)-40:] } - enc.AppendString("[] [" + trimPath + "]") + enc.AppendString("[" + fmt.Sprintf("goid-%d", goid.Get()) + "]" + "[" + trimPath + "]") } zCore := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderConfig), zapcore.NewMultiWriteSyncer(zapcore.AddSync(&hook)), zapLevel) zapLogger = zap.New(zCore, zap.AddCaller(), zap.Development())