Merge pull request 'Add request logging to panic recovery' (#63) from issue-61 into master
This commit is contained in:
commit
bbfe64a3a2
@ -30,11 +30,15 @@ func (rl *rushlink) RootURL() *url.URL {
|
|||||||
|
|
||||||
func (rl *rushlink) recoveryMiddleware(next http.Handler) http.Handler {
|
func (rl *rushlink) recoveryMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
logRequestInfo := func() {
|
||||||
|
log.Printf("in request: %v - %v %q %v", r.RemoteAddr, r.Method, r.RequestURI, r.Proto)
|
||||||
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
log.Printf("error: panic while recovering from another panic: %v\n", err)
|
log.Printf("error: panic while recovering from another panic: %v\n", err)
|
||||||
|
logRequestInfo()
|
||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
fmt.Fprintf(w, "internal server error: %v\n", err)
|
fmt.Fprintf(w, "internal server error: %v\n", err)
|
||||||
}
|
}
|
||||||
@ -43,6 +47,7 @@ func (rl *rushlink) recoveryMiddleware(next http.Handler) http.Handler {
|
|||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
log.Printf("error: %v\n", err)
|
log.Printf("error: %v\n", err)
|
||||||
|
logRequestInfo()
|
||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
rl.renderInternalServerError(w, r, err)
|
rl.renderInternalServerError(w, r, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user