feat: Logger: log X-Real-IP when behind rProxy

This commit is contained in:
HeshamTB 2023-09-12 00:52:54 +03:00
parent 3c5aa3d575
commit 1fd65a5827

View File

@ -32,7 +32,12 @@ func (l *Logger) ServeHTTP(w http.ResponseWriter, r *http.Request) {
tNow := time.Now().UTC()
l.Handler.ServeHTTP(w, r)
methodString := l.getMethodLogString(r.Method)
log.Printf(" %s %s %s %v", r.RemoteAddr, methodString, r.URL, time.Since(tNow))
remote := r.RemoteAddr
realIP := r.Header.Get("X-Real-IP")
if realIP != "" {
remote = realIP
}
log.Printf(" %s %s %s %v", remote, methodString, r.URL, time.Since(tNow))
}
func (l *Logger) getMethodLogString(method string) string {