Skip to content

Commit

Permalink
Merge branch 'master' into riverside-master
Browse files Browse the repository at this point in the history
* master:
  make context.Keys available as LogFormatterParams (gin-gonic#1779)
  spell check  (gin-gonic#1796)
  chore: use internal/json (gin-gonic#1791)
  • Loading branch information
wybcp committed Mar 7, 2019
2 parents cf0583a + 3dc2478 commit 0850387
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type LogFormatterParams struct {
IsTerm bool
// BodySize is the size of the Response Body
BodySize int
// Keys are the keys set on the request's context.
Keys map[string]interface{}
}

// StatusCodeColor is the ANSI color for appropriately logging http status code to a terminal.
Expand Down Expand Up @@ -227,6 +229,7 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
param := LogFormatterParams{
Request: c.Request,
IsTerm: isTerm,
Keys: c.Keys,
}

// Stop timer
Expand Down
4 changes: 4 additions & 0 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func TestLoggerWithFormatter(t *testing.T) {

func TestLoggerWithConfigFormatting(t *testing.T) {
var gotParam LogFormatterParams
var gotKeys map[string]interface{}
buffer := new(bytes.Buffer)

router := New()
Expand All @@ -204,6 +205,7 @@ func TestLoggerWithConfigFormatting(t *testing.T) {
router.GET("/example", func(c *Context) {
// set dummy ClientIP
c.Request.Header.Set("X-Forwarded-For", "20.20.20.20")
gotKeys = c.Keys
})
performRequest(router, "GET", "/example?a=100")

Expand All @@ -223,6 +225,8 @@ func TestLoggerWithConfigFormatting(t *testing.T) {
assert.Equal(t, "GET", gotParam.Method)
assert.Equal(t, "/example?a=100", gotParam.Path)
assert.Empty(t, gotParam.ErrorMessage)
assert.Empty(t, gotParam.ErrorMessage)
assert.Equal(t, gotKeys, gotParam.Keys)

}

Expand Down

0 comments on commit 0850387

Please sign in to comment.