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
@ -45,15 +45,24 @@ 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 time.Time
StatusCode int
Latency time.Duration
ClientIP string
Method string
Path string
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 bool
// IsTerm shows whether does gin's output descriptor refers to a terminal.
IsTerm bool
}
// defaultLogFormatter is the default log format function Logger middleware uses.
@ -114,8 +123,8 @@ func LoggerWithFormatter(f LogFormatter) HandlerFunc {
// Example: os.Stdout, a file opened in write mode, a socket...
func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
return LoggerWithConfig(LoggerConfig{
Output: out,
SkipPathes: notlogged,
Output: out,
SkipPaths: notlogged,
})
}
@ -131,7 +140,7 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
out = DefaultWriter
}
notlogged := conf.SkipPathes
notlogged := conf.SkipPaths
isTerm := true

View File

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