【发布时间】:2014-10-14 16:42:30
【问题描述】:
我希望我的应用程序在调试级别运行,但 Spring 除外,它会产生大量的日志记录语句,这使得阅读日志变得很困难。我目前已经像这样配置了我的 Log4j2 文件:
<Configuration status="debug">
<Appenders>
<RollingFile name="systemLog" fileName="C:/test/logs/system.log" includeLocation="true"
filePattern=""C:/test/logs/system-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout pattern="%d{ISO8601} - %-5level [%t] %C %M %m%n" />
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="15 MB"/>
</Policies>
</RollingFile>
<Async name="systemAsyncAppender" includeLocation="true">
<AppenderRef ref="systemLog" />
</Async>
</Appenders>
<Loggers>
<SpringLogger name="org.springframework.*" level="error" additivity="false">
<AppenderRef ref="systemAsyncAppender" />
</SpringLogger>
<Root level="debug" includeLocation="true">
<AppenderRef ref="systemAsyncAppender" />
</Root>
</Loggers>
</Configuration>
我认为设置 SpringLogger 会将 Spring 设置为仅在 ERROR 级别运行,并且写入与其他所有内容相同的日志,但我仍然看到完整的 Spring DEBUG 输出。我对使用旧的log4j.properties 文件(我认为它就像log4j.category.org.springframework=ERROR 一样简单)很容易做到这一点有模糊的记忆,但我不确定如何使用 Log4J2 做到这一点。
(使用 Log4J2 2.0.2,spring 3.2.11)
【问题讨论】:
-
我在任何地方都没有看到
<SpringLogger>元素。为什么不声明一个普通的<logger>和name="org.springframework"(注意没有*)? -
@SotiriosDelimanolis:
/facepalm是的……就是这样。出于某种原因,我认为我需要给记录器自己的 element 名称。太棒了! :P 你的建议奏效了,所以如果你把它写成答案,我会接受它。