调试Spring配置不起作用

时间:2016-01-15 13:44:08

标签: java spring log4j

我在may Spring应用程序中添加了安全问题所以我想通过log4j调试Spring。

Log4j正在运行,因为我的服务正在将调试信息记录到控制台。 但Spring没有将任何内容记录到我的控制台

这是我的log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
    <appender name="CA" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{MM/dd/yy - HH\:mm\:ss,SSS} [%t] %-5p %c %x - %m%n" />
        </layout>
    </appender>
    <logger name="org.springframework" additivity="false">
        <level value="DEBUG"/>
        <appender-ref ref="CA"/>
    </logger>   
    <logger name="com.test" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="CA"/>
    </logger>
</log4j:configuration>

因为我把--Dlog4j.debug放在我的服务器启动选项中,所以要考虑到这一点。结果:

log4j: Preferred configurator class: org.apache.log4j.xml.DOMConfigurator
log4j: System property is :null
log4j: Standard DocumentBuilderFactory search succeded.
log4j: DocumentBuilderFactory is: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
log4j: debug attribute= "null".
log4j: Ignoring debug attribute.
log4j: reset attribute= "false".
log4j: Threshold ="null".
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [org.springframework] additivity to [false].
log4j: Level value for org.springframework is  [DEBUG].
log4j: org.springframework level set to DEBUG
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{MM/dd/yy - HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n].
log4j: Adding appender named [CA] to category [org.springframework].
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [com.test] additivity to [false].
log4j: Level value for com.testis  [INFO].
log4j: com.testlevel set to INFO
log4j: Adding appender named [CA] to category [com.test].
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: System property is :null
log4j: Standard DocumentBuilderFactory search succeded.
log4j: DocumentBuilderFactory is: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
log4j: debug attribute= "null".
log4j: Ignoring debug attribute.
log4j: reset attribute= "false".
log4j: Threshold ="null".
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [org.springframework] additivity to [false].
log4j: Level value for org.springframework is  [DEBUG].
log4j: org.springframework level set to DEBUG
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{MM/dd/yy - HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n].
log4j: Adding appender named [CA] to category [org.springframework].
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [com.test] additivity to [false].
log4j: Level value for com.test is  [INFO].
log4j: com.test level set to INFO
log4j: Adding appender named [CA] to category [com.test].

我尝试在我的web.xml中添加此内容,如question

中所述
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/classes/log4j.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

我在其他应用程序中使用了这个调试,我真的没有看到原因...... 谢谢你的帮助

1 个答案:

答案 0 :(得分:1)

我找到了它!

使用-Dorg.apache.commons.logging.diagnostics.dest = STDOUT,您可以调试commons-logging配置。

我发现我的依赖项中的jar(jcl-over-slf4j-1.5.8.jar)有一个META-INF / services / org.apache.commons.logging.LogFactory,它定义了SLF4J的记录器。

因此,添加-Dorg.apache.commons.logging.LogFactory = org.apache.commons.logging.impl.LogFactoryImpl,我将记录器恢复为log4j。