Struts2 with log4j print exception stack information
About configuring STRUTS2 Global exceptions After the console cannot print exception information issues
Java code <global-results> <result name= "error" >/exception/error.jsp</result> </global-res ults> <global-exception-mappings> <exception-mapping exception= "Java.lang.Exceptions" Resul t= "Error"/> <exception-mapping result= "error" exception= "Java.lang.Throwable" ></exception-mapping> </global-exception-mappings>
<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>
After configuration, no try catch in action can print exception information in the console.
After several attempts, the solution is as follows:
The configuration parameters in the Defaultstack interceptor in Struts2 are as follows
Java code <interceptor-ref name= "Defaultstack" > <param name= "exception.logenabled" >true</param> <param name= "Exception.loglevel" >error</param> </interceptor-ref>
<interceptor-ref name= "Defaultstack" >
<param name= "exception.logenabled" >true</param>
<param name= "Exception.loglevel" >error</param>
</interceptor-ref>
Then set the Java code in the log4j with the Log4j.logger.com.opensymphony.xwork2=warn
or Java code log4j.logger.com.opensymphony.xwork2=error
Log4j.logger.com.opensymphony.xwork2=error
You can see the console printing exception information, of course, you need to configure console output in log4j.
Principle: http://www.opensymphony.com/webwork/api/com/opensymphony/xwork/interceptor/ExceptionMappingInterceptor.html
The Exceptionmappinginterceptor interceptor in Xwork by default will print off the exception. That is, by default, only jumps to the exception handling page. We need to open it at development time, which is the parameter we just configured in struts.
The interceptor has three parameters. Java code logenabled (optional)-should exceptions also be logged? (Boolean true|false) logLevel (optional)-What is the log level should the We use (Trace, debug, info, warn, error, fatal)? -Defaut is debug logcategory (optional) – If provided we would use this category (eg. com.mycompany.app). Default is to use Com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor.
logenabled (optional)-should exceptions also be logged? (Boolean True|false)
LogLevel (optional)-What is 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). Default is to use Com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor.
Logenabled configuring whether to turn on log output
The LogLevel configuration intercepts the log level to the exception.
Logcategory should be a custom log. There is no use, there is a need to study their own research. Have to know the use of the reply to me ah. Oh
----------------------------------------------------------------------------------Java Code <interceptors> <interceptor name= "Authority" class= "Com.test.SystemInterceptor" /> <interceptor-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> </interceptors> <default-interceptor-ref name= "Myauth" />