简体   繁体   English

LOG4j Spring AOP

[英]LOG4j Spring AOP

I have a j2ee web application running on Spring framework. 我有一个在Spring框架上运行的j2ee Web应用程序。 I want to implement logging using log4j and Spring's AOP. 我想使用log4j和Spring的AOP实现日志记录。 I was trying to find for references but I only get references which does not use log4j. 我试图查找参考,但是我只得到不使用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. 我也声明了要在其中实现日志记录的bean。 The beans id is ExecuteBLogic so I put below *BLogic bean的ID是ExecuteBLogic,所以我在* 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>

There are many examples that show how to log information using spring AOP. 有许多示例显示了如何使用spring AOP记录信息。 The fact that they are using System.out or java.util.logging should bother you - just replace these lines with log4j lines. 他们正在使用System.outjava.util.logging的事实应该困扰您-只需将这些行替换为log4j行即可。

So, ontop of the class: 因此,在课堂上最重要的是:

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

and then instead of System.out.println(..) : 然后代替System.out.println(..)

logger.info(..);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM