From f63a354b40991d77b0488553b5a54f2d320ee0e8 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Sun, 13 Jul 2014 00:18:33 +0200 Subject: [PATCH] Normal log and error log are printed in the same call. --- gin.go | 3 +++ logger.go | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/gin.go b/gin.go index 00b07d5..020b66d 100644 --- a/gin.go +++ b/gin.go @@ -113,6 +113,9 @@ func (a errorMsgs) ByType(typ uint32) errorMsgs { } func (a errorMsgs) String() string { + if len(a) == 0 { + return "" + } var buffer bytes.Buffer for i, msg := range a { text := fmt.Sprintf("Error #%02d: %s \n Meta: %v\n", (i + 1), msg.Err, msg.Meta) diff --git a/logger.go b/logger.go index e141778..5a67f7c 100644 --- a/logger.go +++ b/logger.go @@ -67,17 +67,13 @@ func Logger() HandlerFunc { } end := time.Now() latency := end.Sub(start) - stdlogger.Printf("[GIN] %v |%s %3d %s| %12v | %s %4s %s\n", + stdlogger.Printf("[GIN] %v |%s %3d %s| %12v | %s %4s %s\n%s", end.Format("2006/01/02 - 15:04:05"), color, code, reset, latency, requester, c.Request.Method, c.Request.URL.Path, + c.Errors.String(), ) - - // Calculate resolution time - if len(c.Errors) > 0 { - stdlogger.Println(c.Errors.String()) - } } }