From b3c77882b66ab48c901d471fe854827e016219bb Mon Sep 17 00:00:00 2001 From: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> Date: Tue, 28 Nov 2023 03:43:59 +0100 Subject: [PATCH] chore: logging full path including query params (#61) --- logger.go | 2 +- logger_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/logger.go b/logger.go index c8008ed..dff00a0 100644 --- a/logger.go +++ b/logger.go @@ -107,7 +107,7 @@ func SetLogger(opts ...Option) gin.HandlerFunc { l = l.With(). Int("status", c.Writer.Status()). Str("method", c.Request.Method). - Str("path", c.Request.URL.Path). + Str("path", path). Str("ip", c.ClientIP()). Dur("latency", latency). Str("user_agent", c.Request.UserAgent()).Logger() diff --git a/logger_test.go b/logger_test.go index ccc332d..0bf0e35 100644 --- a/logger_test.go +++ b/logger_test.go @@ -50,6 +50,7 @@ func TestLogger(t *testing.T) { assert.Contains(t, buffer.String(), "200") assert.Contains(t, buffer.String(), "GET") assert.Contains(t, buffer.String(), "/example") + assert.Contains(t, buffer.String(), "path=/example?a=100") buffer.Reset() performRequest(r, "POST", "/example?a=100") @@ -57,6 +58,7 @@ func TestLogger(t *testing.T) { assert.Contains(t, buffer.String(), "POST") assert.Contains(t, buffer.String(), "/example") assert.Contains(t, buffer.String(), "WRN") + assert.Contains(t, buffer.String(), "path=/example?a=100") buffer.Reset() performRequest(r, "PUT", "/example?a=100") @@ -64,6 +66,7 @@ func TestLogger(t *testing.T) { assert.Contains(t, buffer.String(), "PUT") assert.Contains(t, buffer.String(), "/example") assert.Contains(t, buffer.String(), "ERR") + assert.Contains(t, buffer.String(), "path=/example?a=100") } func TestLoggerWithLogger(t *testing.T) {