diff --git a/logger.go b/logger.go index d020ee71..dbd3c1ea 100644 --- a/logger.go +++ b/logger.go @@ -1,19 +1,19 @@ package gin import ( + "fmt" "log" "time" ) func ErrorLogger() HandlerFunc { return func(c *Context) { - defer func() { - if len(c.Errors) > 0 { - log.Println(c.Errors) - c.JSON(-1, c.Errors) - } - }() c.Next() + + if len(c.Errors) > 0 { + // -1 status code = do not change current one + c.JSON(-1, c.Errors) + } } } @@ -28,5 +28,8 @@ func Logger() HandlerFunc { // Calculate resolution time log.Printf("%s in %v", c.Req.RequestURI, time.Since(t)) + if len(c.Errors) > 0 { + fmt.Println(c.Errors) + } } }