mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
refactor(logging): inline request id in log output
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user