Skip to content

Commit

Permalink
log http call timing
Browse files Browse the repository at this point in the history
  • Loading branch information
drypa committed Mar 24, 2024
1 parent 3f5b434 commit f261901
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions backend/logging/middleware.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package logging

import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"time"
)

// RoundTripper implements the http.RoundTripper interface
Expand All @@ -16,14 +17,14 @@ func (lrt RoundTripper) RoundTrip(req *http.Request) (res *http.Response, err er
if err != nil {
return
}
fmt.Printf("%s", dump)

log.Printf("%s", dump)
start := time.Now()
res, err = lrt.Proxied.RoundTrip(req)

elapsed := time.Since(start)
if err != nil {
fmt.Printf("Error %s %s: %v", req.Method, req.URL.RawQuery, err)
log.Printf("Error %s %s took %s: %v", req.Method, req.URL.RawQuery, elapsed, err)
} else {
fmt.Printf("Received %v response\n", res.Status)
log.Printf("Received %v in %s\n", res.Status, elapsed)
}

return
Expand Down

0 comments on commit f261901

Please sign in to comment.