我正在学习 Log4j,我试图理解为什么它会打印两次调试消息?我已阅读有关可加性的信息,并了解日志记录将传播给父级,在本例中为“根”。但是“root”的级别是致命的,所以不应该过滤这个日志请求吗?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<appender name="dataAccessLogger" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%m%n" />
</layout>
</appender>
<logger name="com.supertrooper">
<level value="debug" />
<appender-ref ref="dataAccessLogger" />
</logger>
<root>
<level value="fatal" />
<appender-ref ref="dataAccessLogger" />
</root>
</log4j:configuration>
代码:
// Field in class
private static Logger logger = Logger.getLogger(Log4JTesting.class);
// How I use it
logger.debug("Hello world!-----------------");