当服务器启动时,我在控制台中看到所有正确的 log4j 配置。但是,我没有看到来自 spring 框架的任何日志消息。
此外,我添加了一些输出已定义记录器的代码,并且我看到我的弹簧记录器已定义。为什么我看不到来自 spring 的任何日志消息?
Enumeration loggers = Logger.getDefaultHierarchy().getCurrentLoggers();
while( loggers.hasMoreElements()){
Logger logger = (Logger) loggers.nextElement();
System.out.println(logger.getName()+","+logger.getLevel());
}
SystemOut O org.springframework,DEBUG
我的 web.xml 是(log4j/spring 部分):
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/resource/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
我的 log4j.xml 是:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%5p %d %C{1} - %m%n" />
</layout>
</appender>
<!-- Loggers to filter out various class paths -->
<logger name="org.springframework" additivity="false">
<level value="debug"/>
<appender-ref ref="ConsoleAppender" />
</logger>
</log4j:configuration>
这是我在控制台中看到的:
SystemOut O log4j: System property is :null
SystemOut O log4j: Standard DocumentBuilderFactory search succeded.
SystemOut O log4j: DocumentBuilderFactory is: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
SystemOut O log4j: debug attribute= "true".
SystemOut O log4j: Threshold ="null".
SystemOut O log4j: Retreiving an instance of org.apache.log4j.Logger.
SystemOut O log4j: Setting [org.springframework] additivity to [false].
SystemOut O log4j: Level value for org.springframework is [debug].
SystemOut O log4j: org.springframework level set to DEBUG
SystemOut O log4j: Class name: [org.apache.log4j.ConsoleAppender]
SystemOut O log4j: Setting property [target] to [System.Out].
SystemOut O log4j: Setting property [threshold] to [DEBUG].
SystemOut O log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
SystemOut O log4j: Setting property [conversionPattern] to [%5p %d %C{1} - %m%n].
SystemOut O log4j: Adding appender named [ConsoleAppender] to category [org.springframework].
SystemOut O log4j: Level value for root is [debug].
SystemOut O log4j: root level set to DEBUG
SystemOut O log4j: Adding appender named [ConsoleAppender] to category [root].
我尝试过的事情:
1)从这篇文章中接受的答案
2)我删除了很多我认为可能会干扰 log4j 的 jar。
- 我用 slf4j-log4j.jar 替换了 slf4j-jdk.jar
3)将springs log4j监听器添加到web.xml(也尝试了appcontext.xml中的log4jInitialization bean)