forked from mirror/gin
Normal log and error log are printed in the same call.
This commit is contained in:
parent
e2242b59e6
commit
f63a354b40
3
gin.go
3
gin.go
|
@ -113,6 +113,9 @@ func (a errorMsgs) ByType(typ uint32) errorMsgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a errorMsgs) String() string {
|
func (a errorMsgs) String() string {
|
||||||
|
if len(a) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
for i, msg := range a {
|
for i, msg := range a {
|
||||||
text := fmt.Sprintf("Error #%02d: %s \n Meta: %v\n", (i + 1), msg.Err, msg.Meta)
|
text := fmt.Sprintf("Error #%02d: %s \n Meta: %v\n", (i + 1), msg.Err, msg.Meta)
|
||||||
|
|
|
@ -67,17 +67,13 @@ func Logger() HandlerFunc {
|
||||||
}
|
}
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
latency := end.Sub(start)
|
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"),
|
end.Format("2006/01/02 - 15:04:05"),
|
||||||
color, code, reset,
|
color, code, reset,
|
||||||
latency,
|
latency,
|
||||||
requester,
|
requester,
|
||||||
c.Request.Method, c.Request.URL.Path,
|
c.Request.Method, c.Request.URL.Path,
|
||||||
|
c.Errors.String(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Calculate resolution time
|
|
||||||
if len(c.Errors) > 0 {
|
|
||||||
stdlogger.Println(c.Errors.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue