add gin panic time log (#1270)

* add gin pinic time log

* Update recovery.go
This commit is contained in:
hellojukay 2018-03-20 14:42:51 +08:00 committed by Bo-Yi Wu
parent 3e3f9bca81
commit 65a65c2edd
1 changed files with 7 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
"log"
"net/http/httputil"
"runtime"
"time"
)
var (
@ -38,7 +39,7 @@ func RecoveryWithWriter(out io.Writer) HandlerFunc {
if logger != nil {
stack := stack(3)
httprequest, _ := httputil.DumpRequest(c.Request, false)
logger.Printf("[Recovery] panic recovered:\n%s\n%s\n%s%s", string(httprequest), err, stack, reset)
logger.Printf("[Recovery] %s panic recovered:\n%s\n%s\n%s%s", timeFormat(time.Now()), string(httprequest), err, stack, reset)
}
c.AbortWithStatus(500)
}
@ -107,3 +108,8 @@ func function(pc uintptr) []byte {
name = bytes.Replace(name, centerDot, dot, -1)
return name
}
func timeFormat(t time.Time) string {
var timeString = t.Format("2006/01/02 - 15:04:05")
return timeString
}