Struts2 with log4j print exception stack information

Source: Internet
Author: User
Tags exception handling throwable try catch log4j

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"  />  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.