How to log Client IP and X-Forwarded-For IP in tomcat access log.
I am using %{X-Forwarded-For}i and it logs the actual client address if I access through load bala
You can add these two Valve definition into context.xml. So you can see remote ip in both case. Through load balancer or direct.
org.apache.catalina.valves.RemoteIpValve detects "x-forwarded-for" header. If there is "x-forwarded-for" in header puts its value into "org.apache.tomcat.remoteAddr" request attribute. If there is no "x-forwarded-for" in header puts client ip addr into "org.apache.tomcat.remoteAddr" request attribute.
AccessLogValve config just logs "org.apache.tomcat.remoteAddr" request attribute which holds correct remote ip.