Hi,
I am trying to implement logging in my project. I have used example from
http://www.devx.com/Java/Article/30799/0/page/2 but it is not working. Application works fine and does not throw any exception. But the logging is not happenig
I have carefully read some tutorials but I am not able to solve this problem.
Can someone tell me where am I wrong?
Here are my code snippets
applicationContext.xml
AbcDAOCode:<bean id="AbcServiceBean" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"> <value>com.logic.GenericDAO</value> </property> <property name="target"> <ref bean="AbcDAO"/> </property> <property name="interceptorNames"> <list> <value>loggingInterceptor</value> </list> </property> </bean> <bean id="AbcDAO" class="com.logic.AbcDAO"> <property name="sessionFactory"><ref bean="hibernateSessionFactory" /></property> </bean> <bean id="loggingInterceptor" class="com.web.LoggingInterceptor"/> </beans>
GenericDAOCode:public class AbcDAO extends HibernateDaoSupport implements GenericDAO { ..... .... some business methods .... .... }
Logging interceptor it is basically exactly the same as given in the tutorialCode:public interface GenericDAO { }
Code:public class LoggingInterceptor implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice { private static Logger log = null; public LoggingInterceptor(){ } public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable { log = Logger.getLogger(arg2.getClass()); log.info("Beginning method: "+arg0.getName()); } public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object arg3) throws Throwable { log = Logger.getLogger(arg3.getClass()); log.info("Ending method: "+arg1.getName()); } public void afterThrowing(Method m, Object[] args, Object target, Throwable ex) { log = Logger.getLogger(target.getClass()); log.info("Exception in method: "+m.getName()+" Exception is: "+ex.getMessage()); } }




Reply With Quote

