From 6d43a2ff9a553b84830aeb25a2668c196645b085 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Wed, 24 Dec 2025 21:07:18 +0800 Subject: [PATCH] refactor(logging): inline request id in log output --- internal/logging/gin_logger.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/logging/gin_logger.go b/internal/logging/gin_logger.go index 9bfef8ad..b45a03d7 100644 --- a/internal/logging/gin_logger.go +++ b/internal/logging/gin_logger.go @@ -73,17 +73,15 @@ func GinLogrusLogger() gin.HandlerFunc { method := c.Request.Method errorMessage := c.Errors.ByType(gin.ErrorTypePrivate).String() - logLine := fmt.Sprintf("%3d | %13v | %15s | %-7s \"%s\"", statusCode, latency, clientIP, method, path) + if requestID == "" { + requestID = "--------" + } + logLine := fmt.Sprintf("%3d | %13v | %15s | %s | %-7s \"%s\"", statusCode, latency, clientIP, requestID, method, path) if errorMessage != "" { logLine = logLine + " | " + errorMessage } - var entry *log.Entry - if requestID != "" { - entry = log.WithField("request_id", requestID) - } else { - entry = log.WithField("request_id", "--------") - } + entry := log.NewEntry(log.StandardLogger()) switch { case statusCode >= http.StatusInternalServerError: