Skip to content

Commit ad86f37

Browse files
committed
feat: add debug-level request logging
1 parent 38f0742 commit ad86f37

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func New(options *Options) (http.Handler, func()) {
5656
chitrace.Middleware(),
5757
// Specific routes can specify smaller limits.
5858
httpmw.RateLimitPerMinute(512),
59+
httpmw.DebugLogRequest(api.Logger),
5960
)
6061
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
6162
httpapi.Write(w, http.StatusOK, httpapi.Response{

coderd/httpmw/log.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package httpmw
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
8+
"cdr.dev/slog"
9+
)
10+
11+
func DebugLogRequest(log slog.Logger) func(http.Handler) http.Handler {
12+
return func(next http.Handler) http.Handler {
13+
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
14+
log.Debug(context.Background(), fmt.Sprintf("%s %s", r.Method, r.URL.Path))
15+
next.ServeHTTP(rw, r)
16+
})
17+
}
18+
}

0 commit comments

Comments
 (0)