From 99e44da2e3ef152944aaeb91a04cded16d4ccb30 Mon Sep 17 00:00:00 2001 From: Ghobad Palvaneh Date: Wed, 3 May 2023 10:50:54 +0330 Subject: [PATCH] log skipper --- logger.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/logger.go b/logger.go index cd1e7fa6..7bb051f7 100644 --- a/logger.go +++ b/logger.go @@ -47,8 +47,15 @@ type LoggerConfig struct { // SkipPaths is an url path array which logs are not written. // Optional. 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 type LogFormatter func(params LogFormatterParams) string @@ -239,8 +246,8 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc { // Process request c.Next() - // Log only when path is not being skipped - if _, ok := skip[path]; !ok { + // 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,