feat: add ip address to the logs

This commit is contained in:
2025-02-21 00:36:28 +01:00
parent 5070f591d3
commit 6741aabb26
2 changed files with 5 additions and 1 deletions

View File

@@ -20,11 +20,12 @@ func (w *statusResponseWriter) WriteHeader(code int) {
func Logger(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ips := r.Header.Get("X-Forwarded-For")
rw := newStatusResponseWriter(w)
now := time.Now()
next.ServeHTTP(rw, r)
since := time.Since(now)
log.Println(r.Method, r.URL.Path, r.RemoteAddr, rw.status, since)
log.Println(r.Method, ips, r.URL.Path, rw.status, since)
})
}