【问题标题】:Spring AMQP logs repeating despite disabling in log4j.xml尽管在 log4j.xml 中禁用,但 Spring AMQP 日志仍在重复
【发布时间】:2016-01-01 12:44:02
【问题描述】:

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

01:21:54.323 [SimpleAsyncTaskExecutor-1] 调试 o.s.a.r.l.BlockingQueueConsumer - 为消费者检索交付: tag=[amq.ctag-XAaHUPISVTmjpL-am3y15g], channel=缓存兔频道: AMQChannel(....), 确认模式=自动本地队列大小=0 01:21:55.325 [SimpleAsyncTaskExecutor-1] 调试 o.s.a.r.l.BlockingQueueConsumer - 为消费者检索交付: tag=[amq.ctag-XAaHUPISVTmjpL-am3y15g], channel=缓存兔频道: AMQChannel(....), confirmMode=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>

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

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 的 cmets,我使用 STS 开始了这个项目,并使用了新的 Spring MVC Project,日志文件没有手动配置。项目是否从其他 xml 读取日志文件?

【问题讨论】:

  • 你确定这个配置文件真的在使用吗,例如当您更改模式时,是否会发生更改? (不应该用: 打印DEBUG: 吗?)

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


【解决方案1】:

感谢您指出 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?

【讨论】:

    猜你喜欢
    • 2018-07-16
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 2013-03-23
    相关资源
    最近更新 更多