Struts2 with log4j print exception stack information

Source: Internet
Author: User
Tags try catch log4j

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

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.