Merge branch 'master' into fix-1700

This commit is contained in:
Bo-Yi Wu 2018-12-25 23:30:49 +08:00 committed by GitHub
commit 13357b854f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View File

@ -35,9 +35,9 @@ type LoggerConfig struct {
// Optional. Default value is gin.DefaultWriter.
Output io.Writer
// SkipPathes is a url path array which logs are not written.
// SkipPaths is a url path array which logs are not written.
// Optional.
SkipPathes []string
SkipPaths []string
}
// LogFormatter gives the signature of the formatter function passed to LoggerWithFormatter
@ -46,13 +46,22 @@ type LogFormatter func(params LogFormatterParams) string
// LogFormatterParams is the structure any formatter will be handed when time to log comes
type LogFormatterParams struct {
Request *http.Request
// TimeStamp shows the time after the server returns a response.
TimeStamp time.Time
// StatusCode is HTTP response code.
StatusCode int
// Latency is how much time the server cost to process a certain request.
Latency time.Duration
// ClientIP equals Context's ClientIP method.
ClientIP string
// Method is the HTTP method given to the request.
Method string
// Path is a path the client requests.
Path string
// ErrorMessage is set if error has occurred in processing the request.
ErrorMessage string
// IsTerm shows whether does gin's output descriptor refers to a terminal.
IsTerm bool
}
@ -115,7 +124,7 @@ func LoggerWithFormatter(f LogFormatter) HandlerFunc {
func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
return LoggerWithConfig(LoggerConfig{
Output: out,
SkipPathes: notlogged,
SkipPaths: notlogged,
})
}
@ -131,7 +140,7 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
out = DefaultWriter
}
notlogged := conf.SkipPathes
notlogged := conf.SkipPaths
isTerm := true

View File

@ -321,7 +321,7 @@ func TestLoggerWithConfigSkippingPaths(t *testing.T) {
router := New()
router.Use(LoggerWithConfig(LoggerConfig{
Output: buffer,
SkipPathes: []string{"/skipped"},
SkipPaths: []string{"/skipped"},
}))
router.GET("/logged", func(c *Context) {})
router.GET("/skipped", func(c *Context) {})