feat: add ip address to the logs
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user