refactor(logging): inline request id in log output

This commit is contained in:
hkfires
2025-12-24 21:07:18 +08:00
parent 3faa1ca9af
commit 6d43a2ff9a

View File

@@ -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: