mirror of
1
Fork 0

[bug] Pass context in logging middleware (#1514)

This updates the middleware log.WithField calls that create new loggers
to include the context the first time around. Without it the requestID
does not get logged.

Fixup from #1476
This commit is contained in:
Daenney 2023-02-17 12:37:57 +01:00 committed by GitHub
parent 1ca5c62e25
commit d39280ec33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -57,7 +57,8 @@ func Logger() gin.HandlerFunc {
// Dump a stacktrace to error log
callers := errors.GetCallers(3, 10)
log.WithField("stacktrace", callers).Error(err)
log.WithContext(c.Request.Context()).
WithField("stacktrace", callers).Error(err)
}
// NOTE:
@ -75,7 +76,8 @@ func Logger() gin.HandlerFunc {
fields[5] = kv.Field{"path", path}
// Create log entry with fields
l := log.WithFields(fields...)
l := log.WithContext(c.Request.Context()).
WithFields(fields...)
// Default is info
lvl := level.INFO