I have an application which does logging by LOG4j currently. Recently I tried using Spring AOP concept to do all the logging but it is not logging the details whenever it enters/exits any method. I am able to see the default Spring logs in the log file, but not my logs. Here is my code
for applicationContext.xml
<bean id="input_adapter"
class="org.springframework.aop.framework.ProxyFact oryBean">
<property name="proxyInterfaces">
<value>com.xyz.transaction.util.LoggingMarkerIfc </value>
</property>
<property name="target">
<ref bean="loginputadapter"/>
</property>
<property name="interceptorNames">
<list>
<value>loggingInterceptor</value>
</list>
</property>
</bean>
<bean id="loginputadapter"
class="com.xyz.transaction.adapters.LogInputAdapte r"/>
<bean id="loggingInterceptor"
class="com.xyz.transaction.util.LoggingInterceptor "/>
for the logger class.
public class LoggingInterceptor implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice {
private static Log log = null;
/* public LoggingInterceptor() {
}
*/
public void before(Method arg0, Object[] arg1, Object arg2)
throws Throwable {
log =LogFactory.getLog(arg2.getClass());
log.info("Beginning method: " + arg0.getName());
System.out.println("This is before");
}
public void afterReturning(Object arg0, Method arg1, Object[] arg2,
Object arg3) throws Throwable {
log = LogFactory.getLog(arg3.getClass());
System.out.println("This is after");
log.info("Ending method: " + arg1.getName());
}
public void afterThrowing(Method m, Object[] args, Object target,
Throwable ex) {
log = LogFactory.getLog(target.getClass());
log.info("Exception in method: " + m.getName() + " Exception is: "
+ ex.getMessage());
}
Please help me out if this has anything wrong in it.
Thanks in anticipation


Reply With Quote
