Skip to content

Commit

Permalink
chore: logging full path including query params (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmartinol authored Nov 28, 2023
1 parent 4121d9d commit b3c7788
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,23 @@ 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")
assert.Contains(t, buffer.String(), "400")
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")
assert.Contains(t, buffer.String(), "502")
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) {
Expand Down

0 comments on commit b3c7788

Please sign in to comment.