【问题标题】:How to stop console logging for log4j in spring batch?如何在春季批处理中停止 log4j 的控制台日志记录?
【发布时间】:2015-06-30 12:00:59
【问题描述】:

这是我的 log4j.properties 文件。

log4j.rootCategory=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n

log4j.category.org.springframework.integration=FATAL
log4j.category.org.springframework.batch=FATAL
log4j.category.org.springframework.jdbc=FATAL
log4j.category.org.springframework.transaction=FATAL

我尝试将日志记录级别更改为 INFO、ERROR 等,但没有任何变化。我在 webapp/resources 文件夹中有这个文件,我已经添加了

<context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>classpath:/main/webapp/resources/log4j.properties</param-value>
</context-param>

到 web.xml 也是如此。但是对 log4j.properties 进行更改并没有做任何事情。我仍然可以在这样的控制台中看到许多 DEBUG 日志

17:06:06.405 [qtp2018468405-39] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL query

如何控制日志记录级别?

【问题讨论】:

  • 类路径中的位置值 (classpath:/main/webapp/resources/log4j.properties) 看起来不对。如果您的文件在src/main/webapp/resources 中,它将最终出现在xxx.war!resources/log4j.properties 的WAR 中)。所以你可以试试classpath:/resources/log4j.properties,虽然我不确定classpath:在这里是否正确。
  • 我也试过这个。尝试使用类路径但没有它..但似乎什么也没发生..我还重命名了 log4j.property,但没有错误,日志以相同的方式显示。
  • 所以在启动时添加这个属性,你应该会看到究竟发生了什么(可能是你的文件没有被占用,或者你的附加程序定义错误):-Dlog4j.debug

标签: maven log4j spring-batch


【解决方案1】:

可以通过使用log4j.properties 文件中的log4j.rootLogger 属性来控制日志记录级别。

在您的属性文件中,我看到您没有将log4j.rootLogger 设置为INFO。因此,默认情况下,根记录器被分配给Level.DEBUG

【讨论】:

    最近更新 更多