add gin panic time log (#1270)
* add gin pinic time log * Update recovery.go
This commit is contained in:
parent
3e3f9bca81
commit
65a65c2edd
@ -12,6 +12,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -38,7 +39,7 @@ func RecoveryWithWriter(out io.Writer) HandlerFunc {
|
|||||||
if logger != nil {
|
if logger != nil {
|
||||||
stack := stack(3)
|
stack := stack(3)
|
||||||
httprequest, _ := httputil.DumpRequest(c.Request, false)
|
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)
|
c.AbortWithStatus(500)
|
||||||
}
|
}
|
||||||
@ -107,3 +108,8 @@ func function(pc uintptr) []byte {
|
|||||||
name = bytes.Replace(name, centerDot, dot, -1)
|
name = bytes.Replace(name, centerDot, dot, -1)
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func timeFormat(t time.Time) string {
|
||||||
|
var timeString = t.Format("2006/01/02 - 15:04:05")
|
||||||
|
return timeString
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user