do not call time.now() if logging should be skipped

This commit is contained in:
Ghobad Palvaneh 2023-05-14 17:53:34 +03:30
parent 99e44da2e3
commit 615c50ff2f

View File

@ -238,6 +238,12 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
}
return func(c *Context) {
// Log only when it is not being skipped
if _, ok := skip[c.Request.URL.Path]; ok || (conf.Skip != nil && conf.Skip(c)) {
c.Next()
return
}
// Start timer
start := time.Now()
path := c.Request.URL.Path
@ -246,8 +252,6 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
// Process request
c.Next()
// Log only when it is not being skipped
if _, ok := skip[path]; !ok && conf.Skip != nil && !conf.Skip(c) {
param := LogFormatterParams{
Request: c.Request,
isTerm: isTerm,
@ -274,4 +278,3 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
fmt.Fprint(out, formatter(param))
}
}
}