我有一个log4j2
配置来Sysout控制所有内容+将一般内容记录到application.log
文件+记录error.log
文件的任何例外。
问题:应用程序+错误日志文件中都记录了错误。
org.apache.logging.log4j.Logger.error("Exception log", ex);
以下配置中可能缺少什么?
<Configuration>
<Appenders>
<Console name="CMD" target="SYSTEM_OUT">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<RollingFile name="APPLICATION" fileName="application.log">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</RollingFile>
<RollingFile name="ERR" fileName="error.log">
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="CMD" />
<AppenderRef ref="APPLICATION" />
<AppenderRef ref="ERR" />
</Root>
</Loggers>
</Configuration>
答案 0 :(得分:0)
好的,必须为它组合多个ThresholdFilters
:
<RollingFile name="APPLICATION" fileName="application.log">
<Filters>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</RollingFile>