mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-22 02:15:45 +03:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
d4f0ac2303
2 changed files with 6 additions and 3 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/mholt/caddy/middleware"
|
"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)
|
status, err := h.Next.ServeHTTP(w, r)
|
||||||
|
|
||||||
if err != nil {
|
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 {
|
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
|
// 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)
|
h.errorPage(w, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
const DefaultLogFilename = "error.log"
|
const DefaultLogFilename = "error.log"
|
||||||
|
const timeFormat = "02/Jan/2006:15:04:05 -0700"
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
|
@ -109,7 +110,7 @@ func TestErrors(t *testing.T) {
|
||||||
t.Errorf("Test %d: Expected body %q, but got %q",
|
t.Errorf("Test %d: Expected body %q, but got %q",
|
||||||
i, test.expectedBody, body)
|
i, test.expectedBody, body)
|
||||||
}
|
}
|
||||||
if log := buf.String(); log != test.expectedLog {
|
if log := buf.String(); !strings.Contains(log, test.expectedLog) {
|
||||||
t.Errorf("Test %d: Expected log %q, but got %q",
|
t.Errorf("Test %d: Expected log %q, but got %q",
|
||||||
i, test.expectedLog, log)
|
i, test.expectedLog, log)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue