tags:

views:

434

answers:

1

Hi. I have a j2ee web application running on Spring framework. I want to implement logging using log4j and Spring's AOP. I was trying to find for references but I only get references which does not use log4j.

I had exactly the same configuration as what was on the link you gave. I have declared too a bean which where I want to implement logging. The beans id is ExecuteBLogic so I put below *BLogic

<bean name="methodLoggingInterceptor" class="org.developers.blog.spring.aop.logging.MethodLoggingInterceptor"/>
<bean name="proxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="beanNames">
        <list>
            <value>*BLogic</value>
        </list>
    </property>
    <property name="interceptorNames">
        <list>
            <value>methodLoggingInterceptor</value>
        </list>
    </property>
</bean>
+2  A: 

This and many other examples show how to log information using spring AOP. The fact that they are using System.out or java.util.logging should bother you - just replace these lines with log4j lines.

So, ontop of the class:

private static final Logger logger = Logger.getLogger(LoggingInterceptor.class);

and then instead of System.out.println(..):

logger.info(..);
Bozho
I added the class MethodLoggingInterceptor and declared it as interceptor in my application context. I also copy pasted the proxycreator part supplying here the id of my bean <property name="beanNames"> <list> <value>*BLogic</value> </list> </property>I didn't change anyhting in the interceptor yet. so I ws expecting a printed log on the console. but i get nothing
cedric
does the logging work in other places? Did you run a debugger to see whether your interceptor is activated?
Bozho
i run debugger but it won't enter the interceptor
cedric
then your interceptor is not configured. give your configuration (in your question)
Bozho
I have update above. I added my configuration
cedric
Your configuration seems ok. The problem would be elsewhere but I can't see. Debug additionally.
Bozho
I tried to configure the aop from scratch and it worked. I think I just missed something. Thanks
cedric