0

How can I make wildfly 10 log the request source IP Address? I'm using the default logger. My pattern is:

%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %X{IP} [%c] (%t) %s%e%n

I tried "%a" from some old version 7 documentation but to no avail. Also that %X{IP} doesn't work. (I got it from log4j documentation)

Thank you.

tggm
  • 973
  • 2
  • 15
  • 41

1 Answers1

0

You could use something like %X{IP}, but you'd have to set the MDC value before your log statement and then clear it afterwards. The majority of the logs would have an empty entry for this as they likely don't have an HTTP request associated with them.

If you're using a logging framework that supports MDC something like the following should work from a servlet.

MDC.put("IP", req.getRemoteAddr());
logger.info("This is a test log message");
MDC.remove("IP");  
James R. Perkins
  • 16,800
  • 44
  • 60