Skip to content

Commit

Permalink
Changes behaviour of ErrorLogger() and Logger()
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Jun 30, 2014
1 parent 40dc444 commit bf1ecfc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions logger.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

Expand All @@ -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)
}
}
}

0 comments on commit bf1ecfc

Please sign in to comment.