diff --git a/gin.go b/gin.go index 3834d67e..25f3f694 100644 --- a/gin.go +++ b/gin.go @@ -113,7 +113,7 @@ func New() *Engine { // Default returns an Engine instance with the Logger and Recovery middleware already attached. func Default() *Engine { engine := New() - engine.Use(Recovery(), Logger()) + engine.Use(Logger(), Recovery()) return engine } diff --git a/recovery.go b/recovery.go index e296e339..50a73b6a 100644 --- a/recovery.go +++ b/recovery.go @@ -10,6 +10,7 @@ import ( "io" "io/ioutil" "log" + "net/http/httputil" "runtime" ) @@ -28,14 +29,15 @@ func Recovery() HandlerFunc { func RecoveryWithWriter(out io.Writer) HandlerFunc { var logger *log.Logger if out != nil { - logger = log.New(out, "", log.LstdFlags) + logger = log.New(out, "\n\n\x1b[31m", log.LstdFlags) } return func(c *Context) { defer func() { if err := recover(); err != nil { if logger != nil { stack := stack(3) - logger.Printf("Panic recovery -> %s\n%s\n", err, stack) + httprequest, _ := httputil.DumpRequest(c.Request, false) + logger.Printf("[Recovery] panic recovered:\n%s\n%s\n%s %s", string(httprequest), err, stack, reset) } c.AbortWithStatus(500) }