Skip to content

Commit

Permalink
log now writes to standard error
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewboyle committed Apr 14, 2019
1 parent d8c88e1 commit 00757ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions catchers/log.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion panicMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 00757ae

Please sign in to comment.