【问题标题】:Debugging Spring Configuration doesn't work调试 Spring 配置不起作用
【发布时间】:2016-04-21 03:05:13
【问题描述】:

我在可能的 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].

我尝试按照question 中所述将其添加到我的 web.xml 中

<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>

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

【问题讨论】:

    标签: java spring log4j


    【解决方案1】:

    我找到了!

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

    我发现我的依赖项 (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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-30
      • 2012-11-05
      • 2017-10-08
      • 1970-01-01
      • 2011-12-12
      相关资源
      最近更新 更多