all repos — homestead @ 83369daabc06fafd62316d611baed63fb2900d95

Code for my website

domain/web/server/logging.go (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package server

import (
	"net/http"

	sharedhttp "alin.ovh/homestead/shared/http"

	"alin.ovh/x/log"
)

func wrapHandlerWithLogging(wrappedHandler http.Handler, log *log.Logger) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		lw := sharedhttp.NewStatusCapturingResponseWriter(w)
		wrappedHandler.ServeHTTP(lw, r)
		log.Info(
			"http request",
			"method", r.Method,
			"status", lw.Status,
			"host", r.Host,
			"path", r.URL.Path,
			"location", lw.Header().Get("Location"),
		)
	})
}