mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 13:22:09 +08:00
log skipper
This commit is contained in:
parent
eac2daac64
commit
99e44da2e3
11
logger.go
11
logger.go
@ -47,8 +47,15 @@ type LoggerConfig struct {
|
|||||||
// SkipPaths is an url path array which logs are not written.
|
// SkipPaths is an url path array which logs are not written.
|
||||||
// Optional.
|
// Optional.
|
||||||
SkipPaths []string
|
SkipPaths []string
|
||||||
|
|
||||||
|
// Skip is a Skipper that indicates which logs should not be written.
|
||||||
|
// Optional.
|
||||||
|
Skip Skipper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skipper is a function to skip logs based on provided Context
|
||||||
|
type Skipper func(c *Context) bool
|
||||||
|
|
||||||
// LogFormatter gives the signature of the formatter function passed to LoggerWithFormatter
|
// LogFormatter gives the signature of the formatter function passed to LoggerWithFormatter
|
||||||
type LogFormatter func(params LogFormatterParams) string
|
type LogFormatter func(params LogFormatterParams) string
|
||||||
|
|
||||||
@ -239,8 +246,8 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
|
|||||||
// Process request
|
// Process request
|
||||||
c.Next()
|
c.Next()
|
||||||
|
|
||||||
// Log only when path is not being skipped
|
// Log only when it is not being skipped
|
||||||
if _, ok := skip[path]; !ok {
|
if _, ok := skip[path]; !ok && conf.Skip != nil && !conf.Skip(c) {
|
||||||
param := LogFormatterParams{
|
param := LogFormatterParams{
|
||||||
Request: c.Request,
|
Request: c.Request,
|
||||||
isTerm: isTerm,
|
isTerm: isTerm,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user