问题描述
我想做的很简单:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name = "hibernateFile" fileName = "${artifactId}/logs/hibernate.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
<File name = "springFile" fileName = "${artifactId}/logs/spring.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
<File name = "rootFile" fileName = "${artifactId}/logs/root.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="Console"/>
<AppenderRef ref="rootFile"/>
</Root>
<Logger name ="org.springframework" level = "debug">
<AppenderRef ref = "Console" level = "info"/>
<AppenderRef ref = "springFile" level = "debug"/>
</Logger>
<Logger name ="org.hibernate" level = "debug">
<AppenderRef ref = "Console" level ="info"/>
<AppenderRef ref = "hibernateFile" level = "debug"/>
</Logger>
</Loggers>
</Configuration>
我只希望重要消息显示在控制台附加程序上,而我希望将详细消息路由到文件附加程序.
I want only important messages to be displayed on my Console appender, while I want detailed messages to be routed to the file appenders.
但是,我不想过滤附加器本身-因为我可能希望在其中路由一些调试或跟踪消息(例如,当我在开发中时).
However, I don't want to filter the appender itself - as I may want to route some debugging or trace messages there (for example when I'm in development).
Apache FAQ 建议我可以按日志记录级别进行过滤在 AppenderRef
上,但正如上面xml中所述,我已经尝试过此操作-并且它仍然将DEBUG级别的消息路由到控制台.
The Apache FAQ suggests that I can just filter by logging level on the AppenderRef
, but I've tried this, as outlined in the above xml - and it still routes the DEBUG level messages to the console.
我也尝试过将ThresholdFilter添加到 AppenderRef
中,但这也不能对其进行过滤.
I've also tried adding a ThresholdFilter to the AppenderRef
, but that doesn't filter it either.
<Logger name ="org.hibernate" level = "debug">
<AppenderRef ref = "Console">
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</AppenderRef>
<AppenderRef ref = "hibernateFile" level = "debug"/>
</Logger>
推荐答案
additivity ="false"
应该可以解决问题:
<Logger name="org.hibernate" level="debug" additivity="false">
加性
控制是否将日志事件也仍转发到根记录器.
The additivity
controls whether a log event is also still forwarded to the root logger or not.
这篇关于LOG4J2:多个记录器,到多个附加器,处于不同的记录级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!