myController.java
private static final Logger log = Logger.getLogger(myController.class
.getName());
@GET
@Path("/testDebug")
public String testDebug(@Context final ServletContext context)
{
log.error("This is an error message");
log.debug("This is a debug message");
log.fatal("This is fatal message");
log.warn("This is a warn message");
log.info("This is a info message");
return "Test Page. Debug Mode is on =" + log.isDebugEnabled();
}
jboss-log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
-->
</layout>
</appender>
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<!-- Limit the org.apache category to INFO as its DEBUG is verbose -->
<category name="org.apache">
<priority value="INFO"/>
</category>
<!-- Limit the org.jboss.serial (jboss-serialization) to INFO as its DEBUG is verbose -->
<category name="org.jboss.serial">
<priority value="INFO"/>
</category>
<!-- Limit the org.jgroups category to WARN as its INFO is verbose -->
<category name="org.jgroups">
<priority value="WARN"/>
</category>
<!-- Limit the jacorb category to WARN as its INFO is verbose -->
<category name="jacorb">
<priority value="WARN"/>
</category>
<!-- Limit JBoss categories -->
<category name="org.jboss">
<priority value="INFO"/>
<appender-ref ref="CONSOLE"/>
</category>
<!-- Limit the JSR77 categories -->
<category name="org.jboss.management">
<priority value="INFO"/>
</category>
<!-- This is is the package to myController.java -->
<category name="com.myPackage.src">
<priority value="DEBUG"/>
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
期望的结果
当路径/testDebug
被命中时得到消息:“这是一条调试消息”
问题:
除了调试,我得到所有要显示的消息
10:29:49,440 INFO [STDOUT] 10:29:49,440 ERROR [myController] This is an error message
10:29:49,440 INFO [STDOUT] 10:29:49,440 FATAL [myController] This is fatal message
10:29:49,440 INFO [STDOUT] 10:29:49,440 WARN [myController] This is a warn message
10:29:49,440 INFO [STDOUT] 10:29:49,440 INFO [myController] This is a info message
为什么我无法显示调试消息?