Skip to content

Commit

Permalink
request logging: include status code and duration
Browse files Browse the repository at this point in the history
  • Loading branch information
ns4plabs committed Dec 7, 2023
1 parent dec8d5a commit d473a15
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
_ "embed"
_ "net/http/pprof"

"github.com/felixge/httpsnoop"
"github.com/ipfs/boxo/gateway"
"github.com/ipfs/boxo/path"
servertiming "github.com/mitchellh/go-server-timing"
Expand Down Expand Up @@ -83,9 +84,8 @@ func withConnect(next http.Handler) http.Handler {

func withRequestLogger(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
goLog.Infow(r.Method, "url", r.URL, "host", r.Host)
// TODO: if debug is enabled, show more? goLog.Infow("request received", "url", r.URL, "host", r.Host, "method", r.Method, "ua", r.UserAgent(), "referer", r.Referer())
next.ServeHTTP(w, r)
m := httpsnoop.CaptureMetrics(next, w, r)
goLog.Infow(r.Method, "url", r.URL, "host", r.Host, "code", m.Code, "duration", m.Duration, "written", m.Written, "ua", r.UserAgent(), "referer", r.Referer())

Check warning on line 88 in handlers.go

View check run for this annotation

Codecov / codecov/patch

handlers.go#L87-L88

Added lines #L87 - L88 were not covered by tests
})
}

Expand Down

0 comments on commit d473a15

Please sign in to comment.