From 19f683caae6de4fc1dc328dc0570802ebe544c8b Mon Sep 17 00:00:00 2001 From: loveuer Date: Thu, 18 Jul 2024 09:51:20 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=95=B4=E7=90=86=20trace=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=20ctx(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/log/log.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/log/log.go b/internal/log/log.go index 7aa9f1e..b70ff22 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -3,16 +3,22 @@ package log import ( "context" "fmt" + "github.com/google/uuid" "github.com/loveuer/nf" ulog "github.com/loveuer/nf/nft/log" ) func _mix(ctx context.Context, msg string) string { if ctx == nil { - return msg + return fmt.Sprintf("%s | %s", uuid.Must(uuid.NewV7()).String(), msg) } - return fmt.Sprintf("%v | %s", ctx.Value(nf.TraceKey), msg) + traceId := ctx.Value(nf.TraceKey) + if traceId == nil { + return fmt.Sprintf("%s | %s", uuid.Must(uuid.NewV7()).String(), msg) + } + + return fmt.Sprintf("%s | %s", traceId, msg) } func Debug(ctx context.Context, msg string, data ...any) {