commit d39280ec3389a701604febb221d3e563a9a2c62f
parent 1ca5c62e25d00e054a8e4bf4d8a06c3e69cae85f
Author: Daenney <daenney@users.noreply.github.com>
Date: Fri, 17 Feb 2023 12:37:57 +0100
[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
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/internal/middleware/logger.go b/internal/middleware/logger.go
@@ -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