refactor(logging): standardize request id formatting and layout

This commit is contained in:
hkfires
2025-12-24 22:03:07 +08:00
parent 99238a4b59
commit 5ba325a8fc
2 changed files with 6 additions and 10 deletions

View File

@@ -76,12 +76,12 @@ func GinLogrusLogger() gin.HandlerFunc {
if requestID == "" {
requestID = "--------"
}
logLine := fmt.Sprintf("%3d | %13v | %15s | %s | %-7s \"%s\"", statusCode, latency, clientIP, requestID, method, path)
logLine := fmt.Sprintf("%3d | %13v | %15s | %-7s \"%s\"", statusCode, latency, clientIP, method, path)
if errorMessage != "" {
logLine = logLine + " | " + errorMessage
}
entry := log.NewEntry(log.StandardLogger())
entry := log.WithField("request_id", requestID)
switch {
case statusCode >= http.StatusInternalServerError: