Skip to content

Commit

Permalink
Add logging for IP info
Browse files Browse the repository at this point in the history
  • Loading branch information
p0t4t0sandwich committed Apr 8, 2024
1 parent ccb3f76 commit 08f1785
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ func RequestLoggerMiddleware(next http.Handler) http.Handler {
start := time.Now()
wrapped := &WrappedWriter{w, http.StatusOK}
next.ServeHTTP(wrapped, r)
address := r.Header.Get("X-Real-IP")
if address == "" {
address = r.RemoteAddr
}
log.Printf("%s %d %s %s %s", address, wrapped.statusCode, r.Method, r.URL.Path, time.Since(start))
log.Println("X-Forwarded-Host: " + r.Header.Get("X-Forwarded-Host"))
log.Println("X-Forwarded-Proto: " + r.Header.Get("X-Forwarded-Proto"))
log.Println("X-Forwarded-For: " + r.Header.Get("X-Forwarded-For"))
log.Println("X-Real-IP: " + r.Header.Get("X-Real-IP"))

log.Printf("%s %d %s %s %s", r.RemoteAddr, wrapped.statusCode, r.Method, r.URL.Path, time.Since(start))
})
}

Expand Down

0 comments on commit 08f1785

Please sign in to comment.