Skip to content

Commit

Permalink
add gin panic time log (gin-gonic#1270)
Browse files Browse the repository at this point in the history
* add gin pinic time log

* Update recovery.go
  • Loading branch information
hellojukay authored and appleboy committed Mar 20, 2018
1 parent 3e3f9bc commit 65a65c2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"log"
"net/http/httputil"
"runtime"
"time"
)

var (
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}

0 comments on commit 65a65c2

Please sign in to comment.