Log4j XML configuration debug level issue

一个人想着一个人 提交于 2019-12-14 02:30:29

问题


I am using log4j xml configuration for my project, NOT log4j.properties file. I am trying to display debug messages in eclipse console. But it didn't worked out. Instead, info messages are being displayed.

Below is my log4j xml configuration file

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
    <param name="Target" value="System.out"/> 
    <param name="Threshold" value="debug" />
    <layout class="org.apache.log4j.PatternLayout"> 
      <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/> 
    </layout> 
  </appender> 

  <root> 
    <level value ="debug" /> 
    <appender-ref ref="console" /> 
  </root>

</log4j:configuration>

In my code I am checking what log level is set this way

if(LOG.isDebugEnabled()){
            LOG.debug("debug is enabled");
            LOG.info("Debug enabled but using info to display this message");
            System.out.println("sys out debug is enabled");
}

My eclipse console log output is hereunder:

12:08:51,191 INFO  [com.abc.servlets.MainServlet] (http-localhost-127.0.0.1-8080-2) Debug enabled but using info to display this message
12:08:51,192 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) sys out debug is enabled

Additional Information : I am using Jboss App server.

Still working on this, it didn't strike for me where I was wrong.


回答1:


Should it be

<priority value ="debug" />

instead of

<level value ="debug" /> 

in

 <root> 
    <level value ="debug" /> 
    <appender-ref ref="console" /> 
  </root>


来源:https://stackoverflow.com/questions/18780019/log4j-xml-configuration-debug-level-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!