Skip to content

Commit 94ab6f3

Browse files
authored
feat: add debug-level request logging (#923)
This commit adds a small middleware to coderd that logs all requests at DEBUG level.
1 parent 38f0742 commit 94ab6f3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

coderd/coderd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package coderd
22

33
import (
4+
"context"
5+
"fmt"
46
"net/http"
57
"net/url"
68
"sync"
@@ -56,6 +58,7 @@ func New(options *Options) (http.Handler, func()) {
5658
chitrace.Middleware(),
5759
// Specific routes can specify smaller limits.
5860
httpmw.RateLimitPerMinute(512),
61+
debugLogRequest(api.Logger),
5962
)
6063
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
6164
httpapi.Write(w, http.StatusOK, httpapi.Response{
@@ -231,3 +234,12 @@ type api struct {
231234
websocketWaitMutex sync.Mutex
232235
websocketWaitGroup sync.WaitGroup
233236
}
237+
238+
func debugLogRequest(log slog.Logger) func(http.Handler) http.Handler {
239+
return func(next http.Handler) http.Handler {
240+
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
241+
log.Debug(context.Background(), fmt.Sprintf("%s %s", r.Method, r.URL.Path))
242+
next.ServeHTTP(rw, r)
243+
})
244+
}
245+
}

0 commit comments

Comments
 (0)