struts2 - Log4j not logging when an error occured in my struts 2 action class -


in struts 2 application have no stacktrace when error occurs. test in action class created null object on try call method. struts 2 filter shows me error screen excepions mapping correct, in log file have nothing. way add try/catch log.error(e) in catch statement.

struts.xml :

<interceptors>             <interceptor name="authz" class="com.omb.controller.security.authzinterceptor"/>              <interceptor name="params-filter" class="com.opensymphony.xwork2.interceptor.parameterfilterinterceptor"/>             <interceptor name="user" class="com.omb.controller.interceptor.userinterceptor"/>              <interceptor-stack name="defaultstack">                 <interceptor-ref name="exception">                     <param name="exception.logenabled">true</param>                     <param name="exception.loglevel">error</param>                 </interceptor-ref>                 <interceptor-ref name="alias"/>                 <interceptor-ref name="servletconfig"/>                 <interceptor-ref name="i18n"/>                 <interceptor-ref name="chain"/>                 <interceptor-ref name="modeldriven"/>                 <interceptor-ref name="fileupload"/>                 <interceptor-ref name="staticparams"/>                 <interceptor-ref name="conversionerror"/>                 <interceptor-ref name="params"/>                 <interceptor-ref name="authz"/>                 <interceptor-ref name="user"/>                 <interceptor-ref name="prepare"/>                 <interceptor-ref name="validation"/>                 <interceptor-ref name="workflow"/>             </interceptor-stack>         </interceptors>          <default-interceptor-ref name="defaultstack"/>          <global-results>             <result name="technicalerror" type="chain">erroraction</result>             <result name="sessioninvaliderror" type="tiles">sessioninvalid</result>             <result name="blank" type="tiles">blank</result>         </global-results>          <global-exception-mappings>             <exception-mapping exception="java.lang.exception" result="technicalerror"/>             <exception-mapping exception="com.omb.service.exception.usersessioninvalidexception" result="sessioninvaliderror"/>          </global-exception-mappings> 

log4j.xml :

<appender name="console" class="org.apache.log4j.consoleappender">     <param name="target" value="system.out"/>     <layout class="org.apache.patternlayout">         <param name="conversionpattern" value="%-5p %c{1} - %m%n"/>     </layout> </appender> <appender name="file" class="org.apache.log4j.fileappender">     <param name="file" value="${application.log4j.filename}"/>     <param name="append" value="true"/>     <layout class="org.apache.log4j.patternlayout">         <param name="conversionpattern" value="%d{date}|%-5p|%37c|%m%n"/>     </layout> </appender> <appender name="dailyfile" class="org.apache.log4j.dailyrollingfileappender">     <param name="file" value="${application.log4j.filename}"/>     <param name="append" value="true"/>     <param name="datepattern" value="'.'yyyy-mm-dd"/>     <layout class="org.apache.log4j.patternlayout">         <param name="conversionpattern" value="%d{date}|%-5p|%37c|%m%n"/>     </layout> </appender>  <root>     <priority value="${application.log4j.logger.root}"/>     <appender-ref ref="dailyfile"/> </root> <logger name="com.opensymphony.xwork2">     <level value="${application.log4j.logger.com.opensymphony.xwork2}"/> </logger> <logger name="org.apache.struts2">     <level value="${application.log4j.logger.org.apache.struts2}"/> </logger> <logger name="org.hibernate">     <level value="error"/> </logger> <logger name="org.springframework">     <level value="error"/> </logger>  <logger name="com.omb">     <level value="${application.log4j.logger.com.accor.scoring}"/> </logger> <logger name="com.omb.mapping.or">     <level value="${application.log4j.logger.com.accor.scoring.mapping.or}"/> </logger> <logger name="org.acegisecurity">     <level value="${application.log4j.category.net.sf.acegisecurity}"/> </logger> <logger name="com.omb.i18n">     <level value="${application.log4j.logger.com.accor.scoring.i18n}"/> </logger> 

action class :

package com.omb.controller.gm;   public class myaction extends actionsupport {      /**      *       * @see com.opensymphony.xwork2.actionsupport#execute()      */     public string execute() {         object ob = null;         ob.tostring();         return success;     }  } 

i found workaround implementing interceptor :

package com.omb.controller.interceptor;  import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory;  import com.opensymphony.xwork2.actioninvocation; import com.opensymphony.xwork2.interceptor.abstractinterceptor;   public class customexceptioninterceptor extends abstractinterceptor {      log logger = logfactory.getlog(customexceptioninterceptor.class);      /**      * @see com.opensymphony.xwork2.interceptor.abstractinterceptor#intercept(com.opensymphony.xwork2.actioninvocation)      */     @override     public string intercept(actioninvocation invocation) {          try {             return invocation.invoke();         } catch (exception ex) {             logger.error(ex.getmessage(), ex);             return "error";         }     } } 

interceptor definition in struts.xml :

<interceptors>             <interceptor name="authz" class="com.omb.controller.security.authzinterceptor"/>              <interceptor name="params-filter" class="com.opensymphony.xwork2.interceptor.parameterfilterinterceptor"/>             <interceptor name="user" class="com.omb.controller.interceptor.userinterceptor"/>             <interceptor name="customexception" class="com.omb.controller.interceptor.customexceptioninterceptor"/>              <interceptor-stack name="defaultstack">                 <interceptor-ref name="exception">                     <param name="exception.logenabled">true</param>                     <param name="exception.loglevel">error</param>                 </interceptor-ref>                 <interceptor-ref name="alias"/>                 <interceptor-ref name="servletconfig"/>                 <interceptor-ref name="i18n"/>                 <interceptor-ref name="chain"/>                 <interceptor-ref name="modeldriven"/>                 <interceptor-ref name="fileupload"/>                 <interceptor-ref name="staticparams"/>                 <interceptor-ref name="conversionerror"/>                 <interceptor-ref name="params"/>                 <interceptor-ref name="authz"/>                 <interceptor-ref name="user"/>                 <interceptor-ref name="prepare"/>                 <interceptor-ref name="validation"/>                 <interceptor-ref name="workflow"/>                 <interceptor-ref name="customexception"/>             </interceptor-stack>         </interceptors> 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -