【问题标题】:log4j - Why is logger.debug not working?log4j - 为什么 logger.debug 不起作用?
【发布时间】:2013-07-01 20:51:37
【问题描述】:

我的 log4j.xml 文件有以下配置:

   <appender name="fileAppender"
           class="org.apache.log4j.DailyRollingFileAppender">
      <param name="Threshold" value="INFO" />
      <!-- Change Log File Root when Environment is Set Up -->
      <param name="File" value="${root}/application.log"/>
    <param name="DatePattern" value=".yyyy-MM-dd" />
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n  %-5p %m%n"/>
      </layout>
   </appender>

   <logger name="db.scheduler" additivity="false" >
      <level value="all"/>
      <appender-ref ref="consoleAppender"/>
      <appender-ref ref="fileAppender"/>
   </logger>

但是。当我做 logger.debug 时,它不会添加任何东西! logger.info 和 logger.error 工作...但不是 logger.debug!

【问题讨论】:

    标签: xml debugging logging configuration log4j


    【解决方案1】:
    <param name="Threshold" value="INFO" />
    

    您的阈值设置为INFO,这是低于DEBUG 的一级,因此任何调试消息都不会通过过滤器。相关等级见here

    Level       Description
    =====       ===========
    OFF         The highest possible rank and is intended to
                turn off logging.
    FATAL       Severe errors that cause premature termination.
                Expect these to be immediately visible on a
                status console.
    ERROR       Other runtime errors or unexpected conditions.
                Expect these to be immediately visible on a
                status console.
    WARN        Use of deprecated APIs, poor use of API,
                'almost' errors, other runtime situations that
                are undesirable or unexpected, but not
                necessarily "wrong". Expect these to be
                immediately visible on a status console.
    INFO        Interesting runtime events (startup or
                shutdown). Expect these to be immediately
                visible on a console, so be conservative
                and keep to a minimum.
    DEBUG       Detailed information on the flow through
                the system. Expect these to be written to logs
                only.
    TRACE       Most detailed information. Expect these to be
                written to logs only. Since version 1.2.12.
    

    【讨论】:

    • 所以我应该把它改成 ALL 吗?
    • @gran_profaci,没有。如果您想要调试消息,请将其更改为 debugall 也会为您提供跟踪消息(您可能很想要,但您的问题是专门针对 logger.debug 提出的)。如果您想查看所有内容,并且不介意浏览大量数据,请务必使用跟踪。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 1970-01-01
    • 2020-10-02
    • 2011-01-20
    • 1970-01-01
    相关资源
    最近更新 更多