Skip to content

Commit

Permalink
Adding some additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
madflojo committed May 2, 2020
1 parent 14500e0 commit 10b18ab
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/server.go
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/julienschmidt/httprouter"
"github.com/madflojo/mockitout/mocks"
"github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
)

Expand Down Expand Up @@ -64,12 +65,24 @@ func (s *server) MockHandler(w http.ResponseWriter, r *http.Request, ps httprout
// them. e.g. Metrics, Logging...
func (s *server) middleware(n httprouter.Handle) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// Log the basics
log.WithFields(logrus.Fields{
"method": r.Method,
"remote-addr": r.RemoteAddr,
"http-protocol": r.Proto,
"headers": r.Header,
"method": r.Method,
"remote-addr": r.RemoteAddr,
"http-protocol": r.Proto,
"headers": r.Header,
"content-length": r.ContentLength,
}).Debugf("HTTP Request to %s", r.URL)

if r.ContentLength > 0 {
// Dump payload into logs for visibility
b, err := ioutil.ReadAll(r.Body)
if err == nil {
log.Debugf("Dumping Payload for request to %s: %s", r.URL, b)
}
}

// Call registered handler
n(w, r, ps)
}
}

0 comments on commit 10b18ab

Please sign in to comment.