mirror of https://github.com/coder/coder.git
feat: add debug-level request logging (#923)
This commit adds a small middleware to coderd that logs all requests at DEBUG level.
This commit is contained in:
parent
38f074254b
commit
94ab6f3d8e
|
@ -1,6 +1,8 @@
|
|||
package coderd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
@ -56,6 +58,7 @@ func New(options *Options) (http.Handler, func()) {
|
|||
chitrace.Middleware(),
|
||||
// Specific routes can specify smaller limits.
|
||||
httpmw.RateLimitPerMinute(512),
|
||||
debugLogRequest(api.Logger),
|
||||
)
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
httpapi.Write(w, http.StatusOK, httpapi.Response{
|
||||
|
@ -231,3 +234,12 @@ type api struct {
|
|||
websocketWaitMutex sync.Mutex
|
||||
websocketWaitGroup sync.WaitGroup
|
||||
}
|
||||
|
||||
func debugLogRequest(log slog.Logger) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
log.Debug(context.Background(), fmt.Sprintf("%s %s", r.Method, r.URL.Path))
|
||||
next.ServeHTTP(rw, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue