muthiahmerchant
Jul 20th, 2007, 10:05 AM
I am trying to log the start, end and time taken to execute each method. I have the following in applicationContext.xml
<bean id="managerProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNa meAutoProxyCreator">
<property name="beanNames"><value>*Image*</value></property>
<property name="proxyTargetClass"><value>true</value></property>
<property name="interceptorNames">
<list>
<value>myInterceptor</value>
<value>loggingInterceptor</value>
</list>
</property>
</bean>
<bean id="myInterceptor" class="com.company.interceptor.MyInterceptor" />
<bean id="loggingInterceptor" class="org.springframework.aop.interceptor.SimpleTraceInt erceptor"/>
<bean id="hibImage" class="com.company.grayline.image.HibImageImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
MyInterceptor code looks like this
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyInterceptor implements MethodInterceptor {
private final Log logger = LogFactory.getLog("MAIN");
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
if(logger.isInfoEnabled()){
logger.info("********Beginning method: " + methodInvocation.getMethod().getDeclaringClass() + "::" + methodInvocation.getMethod().getName());
}
long startTime = System.currentTimeMillis();
try {
Object retVal = methodInvocation.proceed();
return retVal;
} finally {
if(logger.isInfoEnabled()){
logger.info(">>>>>>>>>>>>>Method invocation time: " + (System.currentTimeMillis() - startTime) + " msecs.");
logger.info("##########Ending method: " + methodInvocation.getMethod().getDeclaringClass() + "::" + methodInvocation.getMethod().getName());
}
}
}
}
it does not log anything. Can anyone point out what is that I am doing wrong.
Thanks
<bean id="managerProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNa meAutoProxyCreator">
<property name="beanNames"><value>*Image*</value></property>
<property name="proxyTargetClass"><value>true</value></property>
<property name="interceptorNames">
<list>
<value>myInterceptor</value>
<value>loggingInterceptor</value>
</list>
</property>
</bean>
<bean id="myInterceptor" class="com.company.interceptor.MyInterceptor" />
<bean id="loggingInterceptor" class="org.springframework.aop.interceptor.SimpleTraceInt erceptor"/>
<bean id="hibImage" class="com.company.grayline.image.HibImageImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
MyInterceptor code looks like this
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyInterceptor implements MethodInterceptor {
private final Log logger = LogFactory.getLog("MAIN");
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
if(logger.isInfoEnabled()){
logger.info("********Beginning method: " + methodInvocation.getMethod().getDeclaringClass() + "::" + methodInvocation.getMethod().getName());
}
long startTime = System.currentTimeMillis();
try {
Object retVal = methodInvocation.proceed();
return retVal;
} finally {
if(logger.isInfoEnabled()){
logger.info(">>>>>>>>>>>>>Method invocation time: " + (System.currentTimeMillis() - startTime) + " msecs.");
logger.info("##########Ending method: " + methodInvocation.getMethod().getDeclaringClass() + "::" + methodInvocation.getMethod().getName());
}
}
}
}
it does not log anything. Can anyone point out what is that I am doing wrong.
Thanks