Results 1 to 4 of 4

Thread: LoggingInterceptor do nothing

  1. #1
    Join Date
    Nov 2006
    Posts
    3

    Default LoggingInterceptor do nothing

    Hello,

    I am a newbee at AOP and try to implement a loggingInterceptor as an aspect. I try it in serveral ways, but it didn't work.
    Have i forget something in the configuration? It registring the interceptor but he do nothing.
    If somebody have an idea, please help
    Code:
    <bean id="traceInterceptor" class="com.yxz.util.TraceInterceptor"/>
    
    <bean id="aspectjPointcut2"class="org.springframework.aop.aspectj.AspectJExpressionPointcut">
      <property name="expression" value="execution(public void save*())"/>
    </bean>
    <bean id="traceAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
      <property name="advice" ref="traceInterceptor"/>
      <property name="pointcut" ref="aspectjPointcut2"/>
    </bean>	
    
    <bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="target" ref="administrationMgr"/>
      <property name="interceptorNames">
        <list>
          <value>traceAdvisor</value>
        </list>
      </property>
    </bean>
    Code:
    public class TraceInterceptor extends CustomizableTraceInterceptor{
    
    	Logger log = Logger.getLogger(HttpRequestInterceptor.class);
    	
    	public TraceInterceptor() {
    		super();
    		// TODO Auto-generated constructor stub
    	}
    	
    	public void setEnterMessage(String enterMessage){
    		enterMessage = "-----------------Beginning $[targetClassShortName]";
    	}
    
    	public void setExceptionMessage(String exceptionMessage) {
    		exceptionMessage = "-----------------Exception in $[targetClassShortName]";
    	}
         
    	public void setExitMessage(String exitMessage){
    			exitMessage = "-------------------Ending $[targetClassShortName]";
    	}
    
    	protected void writeToLog(Log arg0, String arg1) {
    		super.writeToLog(arg0, arg1);
    		log.debug(arg1);
    	}
    	public Object invoke(MethodInvocation arg0) throws Throwable {
    		// TODO Auto-generated method stub
    		return super.invoke(arg0);
    	}
    	
    
    
    }
    Last edited by Karlo1976; Nov 28th, 2006 at 10:56 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    You shouldn't have to extend CustomizableTraceInterceptor. Instead, you may use an instance of it directly as your traceInterceptor bean using snippet such as the following:

    Code:
    <bean id="traceInterceptor" class="org.springframework.aop.interceptor.CustomizableTraceInterceptor">
         <property name="enterMessage" value="-----------------Beginning $[targetClassShortName]"/>
         ... more properties like this if you don't want to use default messages
    </bean>
    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3
    Join Date
    Nov 2006
    Posts
    3

    Default

    Thanks

    But it doesn't work I have no entry from the Interceptor in my ...default/log/server.log

    Should I change the log4j.properties ?
    Code:
    log4j.rootLogger=INFO, stdout, logfile
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
    log4j.appender.logfile=org.apache.log4j.RollingFileAppender
    log4j.appender.logfile.MaxFileSize=512KB
    log4j.appender.logfile.MaxBackupIndex=3
    log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
    log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

  4. #4
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    The interceptor logs the message at the TRACE level, hence you will need to modify your log4j.properties to enable log at this level (currently you are using the INFO level, which isn't sufficient to let trace messages go through).

    Please refer to the documentation for CustomizableTraceInterceptor and AbstractTraceInterceptor.

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •