feat(logger): ability to skip logs based on user-defined logic (#3593)
* log skipper * do not call time.now() if logging should be skipped * do not ignore skip func delay in latency calculation * write docs * write test
This commit is contained in:
@ -415,6 +415,26 @@ func TestLoggerWithConfigSkippingPaths(t *testing.T) {
|
||||
assert.Contains(t, buffer.String(), "")
|
||||
}
|
||||
|
||||
func TestLoggerWithConfigSkipper(t *testing.T) {
|
||||
buffer := new(strings.Builder)
|
||||
router := New()
|
||||
router.Use(LoggerWithConfig(LoggerConfig{
|
||||
Output: buffer,
|
||||
Skip: func(c *Context) bool {
|
||||
return c.Writer.Status() == http.StatusNoContent
|
||||
},
|
||||
}))
|
||||
router.GET("/logged", func(c *Context) { c.Status(http.StatusOK) })
|
||||
router.GET("/skipped", func(c *Context) { c.Status(http.StatusNoContent) })
|
||||
|
||||
PerformRequest(router, "GET", "/logged")
|
||||
assert.Contains(t, buffer.String(), "200")
|
||||
|
||||
buffer.Reset()
|
||||
PerformRequest(router, "GET", "/skipped")
|
||||
assert.Contains(t, buffer.String(), "")
|
||||
}
|
||||
|
||||
func TestDisableConsoleColor(t *testing.T) {
|
||||
New()
|
||||
assert.Equal(t, autoColor, consoleColorMode)
|
||||
|
Reference in New Issue
Block a user