forked from mirror/gin
Changes behaviour of ErrorLogger() and Logger()
This commit is contained in:
parent
40dc444270
commit
bf1ecfcf70
11
logger.go
11
logger.go
|
@ -1,19 +1,19 @@
|
||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ErrorLogger() HandlerFunc {
|
func ErrorLogger() HandlerFunc {
|
||||||
return func(c *Context) {
|
return func(c *Context) {
|
||||||
defer func() {
|
c.Next()
|
||||||
|
|
||||||
if len(c.Errors) > 0 {
|
if len(c.Errors) > 0 {
|
||||||
log.Println(c.Errors)
|
// -1 status code = do not change current one
|
||||||
c.JSON(-1, c.Errors)
|
c.JSON(-1, c.Errors)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
c.Next()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,5 +28,8 @@ func Logger() HandlerFunc {
|
||||||
|
|
||||||
// Calculate resolution time
|
// Calculate resolution time
|
||||||
log.Printf("%s in %v", c.Req.RequestURI, time.Since(t))
|
log.Printf("%s in %v", c.Req.RequestURI, time.Since(t))
|
||||||
|
if len(c.Errors) > 0 {
|
||||||
|
fmt.Println(c.Errors)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue