Skip to content

Commit

Permalink
request logging: include status code and duration (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
ns4plabs authored Feb 9, 2024
1 parent 4da36eb commit d6ad636
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0
github.com/dgraph-io/badger/v4 v4.2.0
github.com/dustin/go-humanize v1.0.1
github.com/felixge/httpsnoop v1.0.4
github.com/ipfs-shipyard/nopfs v0.0.12
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a
Expand Down Expand Up @@ -59,7 +60,6 @@ require (
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/flynn/noise v1.0.1 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand Down
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())
})
}

Expand Down

0 comments on commit d6ad636

Please sign in to comment.