From 00757aefe44a0f62df5ad068b4f0b23a839c9129 Mon Sep 17 00:00:00 2001 From: matthewboyle Date: Sun, 14 Apr 2019 10:09:11 +0100 Subject: [PATCH] log now writes to standard error --- catchers/log.go | 7 +++++-- panicMiddleware.go | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/catchers/log.go b/catchers/log.go index 72c0c5b..03ab313 100644 --- a/catchers/log.go +++ b/catchers/log.go @@ -1,12 +1,15 @@ package catchers -import "fmt" +import ( + "fmt" + "os" +) //Log is a an empty struct that satisfies the PanicHandler interface. type Log struct{} //HandlePanic takes the message and logs it to fmt.println if an unhandled panic occurs within your server. func (l Log) HandlePanic(message string) error { - fmt.Println(message) + fmt.Fprintln(os.Stderr, message) return nil } diff --git a/panicMiddleware.go b/panicMiddleware.go index 32747c9..2dcf3b6 100644 --- a/panicMiddleware.go +++ b/panicMiddleware.go @@ -3,6 +3,7 @@ package goCatch import ( "fmt" "net/http" + "os" ) //PanicHandler is an interface. It is taken by the PanicMiddleware. All PanicHandlers are responsible for dealing with unexpected @@ -19,7 +20,7 @@ func PanicMiddleware(ph PanicHandler, message string, next http.Handler) http.Ha if r := recover(); r != nil { err := ph.HandlePanic(message) if err != nil { - fmt.Printf("panic handler failed to recover from the panic.") + fmt.Fprintln(os.Stderr, "panic handler failed to recover from the panic.") } w.WriteHeader(http.StatusInternalServerError)