My project uses struts2.5.13 + spring5.0.1 + logback1.2.3.
With the new version of logback, child thread no longer inherit MDC values from the master thread, so that error logs in struts2 actions cannot get MDC values.
The basic question may like the following questions:
I had read their solutions but still cannot understand how to solve my problem.
As the following example, I can get MDC by MDC.getCopyOfContextMap(), and set it in execute method. But this only works for the action and method I specified.
public class TestAction extends ActionSupport {
private Logger log=LoggerFactory.getLogger(PatchAction.class);
private Map<String,String> contextMap = MDC.getCopyOfContextMap();
public String testMethod1(){
MDC.setContextMap(contextMap);
log.info("test1");
return "main";
}
public String testMethod2(){
log.info("test2");
return "main";
}
}
In this example, only the logs produced by method1 get the MDC values. The MDC values in logs produced by method2 or other actions would be null.
I want a clearly solution to handle all method in all actions.
How to use MDC with thread pools? shows how to make it true, but I don't know how to integrate with struts2.
I want to know how to wrap the action executor of struts2.