Skip to content

Commit

Permalink
feat(logger): show query string in logger. (gin-gonic#999) close gin-…
Browse files Browse the repository at this point in the history
…gonic#988

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy authored and javierprovecho committed Jul 10, 2017
1 parent fb7448f commit e31cbdf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
// Start timer
start := time.Now()
path := c.Request.URL.Path
raw := c.Request.URL.RawQuery

// Process request
c.Next()
Expand All @@ -97,6 +98,10 @@ func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
}
comment := c.Errors.ByType(ErrorTypePrivate).String()

if raw != "" {
path = path + "?" + raw
}

fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %15s |%s %s %-7s %s\n%s",
end.Format("2006/01/02 - 15:04:05"),
statusColor, statusCode, reset,
Expand Down
3 changes: 2 additions & 1 deletion logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ func TestLogger(t *testing.T) {
router.HEAD("/example", func(c *Context) {})
router.OPTIONS("/example", func(c *Context) {})

performRequest(router, "GET", "/example")
performRequest(router, "GET", "/example?a=100")
assert.Contains(t, buffer.String(), "200")
assert.Contains(t, buffer.String(), "GET")
assert.Contains(t, buffer.String(), "/example")
assert.Contains(t, buffer.String(), "a=100")

// I wrote these first (extending the above) but then realized they are more
// like integration tests because they test the whole logging process rather
Expand Down

0 comments on commit e31cbdf

Please sign in to comment.