From 71c4fdbc851430ae53f6bd155f0cd515aebacdaf Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sun, 5 Jul 2015 21:27:13 -0600 Subject: [PATCH] errors: Prepend timestamp to log entry --- middleware/errors/errors.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/middleware/errors/errors.go b/middleware/errors/errors.go index ce9a7cd8..8f1e04b4 100644 --- a/middleware/errors/errors.go +++ b/middleware/errors/errors.go @@ -9,6 +9,7 @@ import ( "os" "runtime" "strings" + "time" "github.com/mholt/caddy/middleware" ) @@ -27,7 +28,7 @@ func (h ErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er status, err := h.Next.ServeHTTP(w, r) if err != nil { - h.Log.Printf("[ERROR %d %s] %v", status, r.URL.Path, err) + h.Log.Printf("%s [ERROR %d %s] %v", time.Now().Format(timeFormat), status, r.URL.Path, err) } if status >= 400 { @@ -107,8 +108,9 @@ func (h ErrorHandler) recovery(w http.ResponseWriter, r *http.Request) { } // Currently we don't use the function name, as file:line is more conventional - h.Log.Printf("[PANIC %s] %s:%d - %v", r.URL.String(), file, line, rec) + h.Log.Printf("%s [PANIC %s] %s:%d - %v", time.Now().Format(timeFormat), r.URL.String(), file, line, rec) h.errorPage(w, http.StatusInternalServerError) } const DefaultLogFilename = "error.log" +const timeFormat = "02/Jan/2006:15:04:05 -0700"