Struts2 with log4j print exception stack information
About configuring STRUTS2 Global exception the console cannot print exception information issues
<global-results>
<result name= "error" >/exception/error.jsp</result>
</ global-results>
<global-exception-mappings>
<exception-mapping exception= " Java.lang.Exceptions "result=" error "/>
<exception-mapping result=" error "exception=" java.lang.Throwable "></exception-mapping>
</global-exception-mappings>
When configured, the exception information cannot be printed on the console without a try catch in the action.
After multiple attempts the solution is as follows:
The configuration parameters in the Defaultstack interceptor in Struts2 are as follows
<interceptor-ref name= "Defaultstack" >
<param name= "exception.logenabled" >true</param>
<param name= "Exception.loglevel" >error</param>
</interceptor-ref>
And in conjunction with LOG4J set
Or
Log4j.logger.com.opensymphony.xwork2=error
You can see the console printing exception information, and of course log4j needs to configure the console output.
Principle:
Http://www.opensymphony.com/webwork/api/com/opensymphony/xwork/interceptor/ExceptionMappingInterceptor.html
The Exceptionmappinginterceptor interceptor in Xwork closes the exception print by default. That is, by default, only jumps to the exception-handling page. We need to open it at development time, the parameters we have just configured in struts.
The interceptor has three parameters.
logenabled (optional)-Should exceptions also be logged? (Boolean True|false)
LogLevel (optional)-What log level should we use (Trace, debug, info, warn, error, fatal)? -Defaut is debug
logcategory (optional)-If provided we would use this category (eg. com.mycompany.app). The Default is to use Com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor.
Logenabled Configure whether log output is turned on
The loglevel configuration blocks to the log level of the exception.
Logcategory should be a custom log. Not how to use, there is the need to study their own research. Have to know the purpose of the reply to me ah. Oh
<interceptors>
<interceptor name= "authority"
class= "Com.test.SystemInterceptor"/>
<i Nterceptor-stack name= "Myauth" >
<interceptor-ref name= "Defaultstack" >
<param name= "Exception". Logenabled ">true</param>
<param name=" Exception.loglevel ">error</param>
</ interceptor-ref>
<interceptor-ref name= "authority"/>
</interceptor-stack>
</inter ceptors>
<default-interceptor-ref name= "Myauth"/>
Original source: http://tdcq.iteye.com/blog/706459