Include the request ID in the request logs
This commit is contained in:
parent
2968ea3498
commit
464f26a2c9
|
@ -152,8 +152,9 @@ func (re *RequestError) asFilesystemError() (int, string) {
|
|||
func AttachRequestID() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
id := uuid.New().String()
|
||||
c.Header("X-Request-Id", id)
|
||||
c.Set("request_id", id)
|
||||
c.Set("logger", log.WithField("request_id", id))
|
||||
c.Header("X-Request-Id", id)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
@ -311,4 +312,4 @@ func ExtractServer(c *gin.Context) *server.Server {
|
|||
panic("middleware/middleware: cannot extract server: not present in request context")
|
||||
}
|
||||
return v.(*server.Server)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,13 @@ func Configure() *gin.Engine {
|
|||
// lifecycle and quickly seeing what was called leading to the logs. However, it isn't feasible to mix
|
||||
// this output in production and still get meaningful logs from it since they'll likely just be a huge
|
||||
// spamfest.
|
||||
router.Use()
|
||||
router.Use(gin.LoggerWithFormatter(func(params gin.LogFormatterParams) string {
|
||||
log.WithFields(log.Fields{
|
||||
"client_ip": params.ClientIP,
|
||||
"status": params.StatusCode,
|
||||
"latency": params.Latency,
|
||||
"client_ip": params.ClientIP,
|
||||
"status": params.StatusCode,
|
||||
"latency": params.Latency,
|
||||
"request_id": params.Keys["request_id"],
|
||||
}).Debugf("%s %s", params.MethodColor()+params.Method+params.ResetColor(), params.Path)
|
||||
|
||||
return ""
|
||||
|
|
Loading…
Reference in New Issue
Block a user