summaryrefslogtreecommitdiff
path: root/internal/middleware/logger.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-01-09 10:41:15 +0100
committerLibravatar GitHub <noreply@github.com>2024-01-09 10:41:15 +0100
commitaad3384c9891583af2d3421ff19cd20d459f2131 (patch)
treef69e5dca7b87247035cb8e3691b484522b2b8ede /internal/middleware/logger.go
parent[chore]: Bump golang.org/x/image from 0.14.0 to 0.15.0 (#2506) (diff)
downloadgotosocial-aad3384c9891583af2d3421ff19cd20d459f2131.tar.xz
[feature] Log pubKeyID for http-signed requests (#2501)
Diffstat (limited to 'internal/middleware/logger.go')
-rw-r--r--internal/middleware/logger.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/internal/middleware/logger.go b/internal/middleware/logger.go
index 676f9e691..89a0c396d 100644
--- a/internal/middleware/logger.go
+++ b/internal/middleware/logger.go
@@ -28,6 +28,7 @@ import (
"codeberg.org/gruf/go-kv"
"codeberg.org/gruf/go-logger/v2/level"
"github.com/gin-gonic/gin"
+ "github.com/superseriousbusiness/gotosocial/internal/gtscontext"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/log"
)
@@ -77,15 +78,24 @@ func Logger(logClientIP bool) gin.HandlerFunc {
fields[2] = kv.Field{"method", c.Request.Method}
fields[3] = kv.Field{"statusCode", code}
fields[4] = kv.Field{"path", path}
+
+ // Set optional request logging fields.
if logClientIP {
fields = append(fields, kv.Field{
"clientIP", c.ClientIP(),
})
}
+ ctx := c.Request.Context()
+ if pubKeyID := gtscontext.HTTPSignaturePubKeyID(ctx); pubKeyID != nil {
+ fields = append(fields, kv.Field{
+ "pubKeyID", pubKeyID.String(),
+ })
+ }
+
// Create log entry with fields
l := log.New()
- l = l.WithContext(c.Request.Context())
+ l = l.WithContext(ctx)
l = l.WithFields(fields...)
// Default is info