Hi, this is a combination question about both log4j and struts. For the MDC is managed on a per thread basis, we can use it to log the user IP address in the web application. While, as I remember, struts action class is designed to be thread-safe. If I try to log the user IP address in the execute () method of struts action class,
For example public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { String username=session.getAttribute("user"); MDC.put("userip",request.getRemoteAddr()); logger.info(username+" login"); .. } Will the unexpected case happen? 1. UserA from 192.168.0.1 login, and the MDC put 192.168.0.1 to the MDC 2. UserB from 192.168.0.2 login, and the MDC put 192.168.0.2 to the MDC(now the userip in MDC is updated) 3. UserA executed the code logger.info(username+" login"); 4. UserA executed the code logger.info(username+" login"); so the log4j output maybe look like [192.168.0.2] UserA login [192.168.0.2] UserB login Actually the assumption is [192.168.0.1] UserA login [192.168.0.2] UserB login Best Regards Xi Yuxiang System Architect Maveo Systems Limited - www.maveosystems.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]