diff --git a/logging.go b/logging.go index b4248e4..09c94bc 100644 --- a/logging.go +++ b/logging.go @@ -18,7 +18,7 @@ func (l *LoggingHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { l.Handler.ServeHTTP(w, r) log.Println( - fmt.Sprintf("%s %s %s %v", r.RemoteAddr, r.Method, r.URL.Path, time.Since(t1)), + fmt.Sprintf("%s %s %s %v", getIP(r), r.Method, r.URL.Path, time.Since(t1)), ) } @@ -26,3 +26,12 @@ func (l *LoggingHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func NewLogger(handler http.Handler) LoggingHTTPHandler { return LoggingHTTPHandler{handler} } + +func getIP(r *http.Request) string { + + RealIP := r.Header.Get("X-Real-IP") + if RealIP == "" { + return r.RemoteAddr + } + return RealIP +}