尽管在log4j.xml中禁用了Spring AMQP日志重复

时间:2015-10-04 21:50:51

标签: java spring spring-mvc logging spring-amqp

我在使用Spring AMQP时反复收到以下日志:

  

01:21:54.323 [SimpleAsyncTaskExecutor-1] DEBUG   o.s.a.r.l.BlockingQueueConsumer - 检索消费者的递送:   tag = [amq.ctag-XAaHUPISVTmjpL-am3y15g],channel = Cached Rabbit Channel:   AMQChannel(....)   acknowledgeMode = AUTO本地队列大小= 0 01:21:55.325   [SimpleAsyncTaskExecutor-1] DEBUG o.s.a.r.l.BlockingQueueConsumer -   检索消费者的递送:   tag = [amq.ctag-XAaHUPISVTmjpL-am3y15g],channel = Cached Rabbit Channel:   AMQChannel(....)   acknowledgeMode = AUTO本地队列大小= 0 01:21:56.327

我的log.xml文件看起来像这样

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%-5p: %c - %m%n" />
    </layout>
</appender>
....
<logger name="org.springframework.amqp.rabbit">
    <level value="off" />
</logger>

<logger name="org.springframework.amqp">
    <level value="off" />
</logger>
<!-- Root Logger -->
<root>
    <priority value="off" />
    <appender-ref ref="console" />
</root>

</log4j:configuration>

经过仔细检查,我发现BlockingQueueConsumer中的org.springframework.amqp.rabbit类会发出上述日志,确切的行是

if (logger.isDebugEnabled()) {
            logger.debug("Retrieving delivery for " + this);
        } 

我的问题是,鉴于上述log4j.xml条目,这是如何实现的。我错过了什么。我使用以下记录器slf4j-api-1.6.6.jar,slf4j-log4j12-1.6.6.jar,log4j-1.2.15.jar

修改

参考zapl的评论我用STS启动了这个项目并使用了新的Spring MVC Project日志文件没有手动配置。项目是否从其他xml读取日志文件?

1 个答案:

答案 0 :(得分:0)

感谢你指出zapl。我发现了这个问题。在web.xml文件中,您应该提及此

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/resource/log4j.properties</param-value>
</context-param>

 <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

参考这个答案: How to configure the log4j output file path in web.xml and log4j.properties?