From 9d7fea4d82a52e14b2b32b73e284fd3349ac0e27 Mon Sep 17 00:00:00 2001 From: tiglog Date: Tue, 17 Oct 2023 21:06:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E6=96=B9=E4=BE=BF=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logger/log.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/logger/log.go b/logger/log.go index 84da339..b54c13d 100644 --- a/logger/log.go +++ b/logger/log.go @@ -10,6 +10,7 @@ package logger import ( "fmt" "io" + "net/http" "os" "go.uber.org/zap" @@ -96,11 +97,12 @@ func ReplaceDefault(l *Logger) { std = l } func SetLevel(level Level) { std.SetLevel(level) } -func With(fields ...Field) { - std.l.Core().With(fields) +func WithTarget(target string) Field { + return String("target", target) } -func WithRequestId(reqId string) { - std.l.Core().With([]Field{String("reqId", reqId)}) + +func WithRequestId(req *http.Request) Field { + return String("reqId", req.Header.Get("X-Request-ID")) } func Debug(msg string, fields ...Field) { std.Debug(msg, fields...) }