How do I get jboss to display log.debug messages?

16,327

Refer to this question for updated information on seeing debug logging with Jboss 7.1.1+.

Some points:

  1. Your class myController uses the logging as expected. (Another answer claims that you incorrectly instantiated your logger; not true.)

  2. Remove the log4j.xml (or logback.xml etc) configuration file from your project (i.e., from main/resources/META-INF)

  3. In your pom.xml, make sure that your slf4j dependency has a scope of provided (Jboss will provide this). Further, do not include the log4j (or logback etc) implementation dependencies. For example, here's what your logging dependency section may look like:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
        <scope>provided</scope>
    </dependency>
    
  4. Make sure that you have a logger entry for your package in your standalone/configuration/standalone.xml file.

    <logger category="com.myPackage.src">
         <level name="DEBUG"/>
    </logger>
    
  5. Make sure that console-handler and periodic-rotating-file-handler handlers have a level of DEBUG. (By default, they are INFO. They will need to be DEBUG or else your debug statements will be ignored.)

Note, there is a CLI that allows you to update the logging. I do mine manually but it's probably wise to use the CLI.

Here's an abbreviated version of what your standalone.xml logging portion could look like:

    <subsystem xmlns="urn:jboss:domain:logging:2.0">
        <console-handler name="CONSOLE">
            <level name="DEBUG"/>
            <formatter>
                <named-formatter name="COLOR-PATTERN"/>
            </formatter>
        </console-handler>
        <periodic-rotating-file-handler name="FILE" autoflush="true">
            <level name="DEBUG"/>
            <formatter>
                <named-formatter name="PATTERN"/>
            </formatter>
            <file relative-to="jboss.server.log.dir" path="server.log"/>
            <suffix value=".yyyy-MM-dd"/>
            <append value="true"/>
        </periodic-rotating-file-handler>
        <logger category="com.myPackage.src">
            <level name="DEBUG"/>
        </logger>
        <root-logger>
            <level name="INFO"/>
            <handlers>
                <handler name="CONSOLE"/>
                <handler name="FILE"/>
            </handlers>
        </root-logger>
        <formatter name="PATTERN">
            <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
        <formatter name="COLOR-PATTERN">
            <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
    </subsystem>
Share:
16,327
stackoverflow
Author by

stackoverflow

Updated on July 25, 2022

Comments

  • stackoverflow
    stackoverflow almost 2 years

    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>
    

    Desired Result

    when path /testDebug is hit get the message: "This is a debug message"

    Problem:

    I get all message to display except debug

    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
    

    Why cant I get debug message to display?

  • stackoverflow
    stackoverflow almost 12 years
    I added that to my jboss-log4j.xml. Still not working. I am still only getting the other messages and not the debug message. I added your feedback to the initial question
  • ravi
    ravi about 4 years
    Hello Uday do edit your question and specify what you are trying to do. What is the problem that you are facing and what have you tried so far.
  • tfrascaroli
    tfrascaroli about 4 years
    While this answer may contain the necessary information to solve the problem, it is not clear how it does so. Please edit and explain how your answer solves the OP's question.