diff options
author | 2023-02-17 12:37:57 +0100 | |
---|---|---|
committer | 2023-02-17 12:37:57 +0100 | |
commit | d39280ec3389a701604febb221d3e563a9a2c62f (patch) | |
tree | c8fccbffd55f619341037932da24bf1de4abaff6 | |
parent | [bug] maxprocs set logger to nil (#1512) (diff) | |
download | gotosocial-d39280ec3389a701604febb221d3e563a9a2c62f.tar.xz |
[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
-rw-r--r-- | internal/middleware/logger.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/internal/middleware/logger.go b/internal/middleware/logger.go index 6fd7ce2c8..723952eec 100644 --- 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 |