pupate

Puzzle transpiler
git clone https://git.woozle.org/neale/pupate.git

pupate / cmd / cocoon
Neale Pickett  ·  2024-12-20

httplogmux.go

 1package main
 2
 3import (
 4	"log/slog"
 5	"net/http"
 6)
 7
 8// HTTPLogMux is an http.ServeMux that logs requests.
 9type HTTPLogMux struct {
10	*http.ServeMux
11}
12
13func NewHTTPLogMux() *HTTPLogMux {
14	return &HTTPLogMux{http.NewServeMux()}
15}
16
17// ServeHTTP passes the request to h.ServeMux, then logs it
18func (h *HTTPLogMux) ServeHTTP(w http.ResponseWriter, req *http.Request) {
19	slog.Debug("HTTP request",
20		"addr", req.RemoteAddr,
21		"method", req.Method,
22		"URL", req.URL,
23	)
24	h.ServeMux.ServeHTTP(w, req)
25}