stackoverflow
stackoverflow

Reputation: 19454

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

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?

Upvotes: 3

Views: 19755

Answers (4)

Uday Yadav
Uday Yadav

Reputation: 1

Detailed information could be found at: https://docs.jboss.org/author/display/AS71/Logging+Configuration
<subsystem xmlns="urn:jboss:domain:logging:1.0">
   <console-handler name="CONSOLE" autoflush="true">
       <level name="DEBUG"/>
       <formatter>
           <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
       </formatter>
   </console-handler>
   <periodic-rotating-file-handler name="FILE" autoflush="true">
       <formatter>
           <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
       </formatter>
       <file relative-to="jboss.server.log.dir" path="server.log"/>
       <suffix value=".yyyy-MM-dd"/>
   </periodic-rotating-file-handler>
   <logger category="com.arjuna">
       <level name="WARN"/>
   </logger>
   [...]
   <root-logger>
       <level name="DEBUG"/>
       <handlers>
           <handler name="CONSOLE"/>
           <handler name="FILE"/>
       </handlers>
   </root-logger>
</subsystem>

1.the changes can be made in standalone.xml 2.the above solution is to show how to see the debug messages of logs in jboss this will solve the above problem

Upvotes: -1

whyceewhite
whyceewhite

Reputation: 6425

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>

Upvotes: 5

James R. Perkins
James R. Perkins

Reputation: 17780

Your category is defined incorrectly. When you instantiate your logger you're using Class.getName() which returns the fully qualified class name. You define your logger category with only the package name which means debugging is not turned on for the category com.myPackage.src.myController.

You need to either change the way you instantiate your logger

private static final Logger log = Logger.getLogger(myController.class.getPackage().getName());

or change your category definition

<category name="com.myPackage.src.myController">
  <priority value="DEBUG"/>
</category>

On a side not, packages should not have uppercase characters and class names should always begin with an uppercase letter.

Upvotes: 0

Suraj Chandran
Suraj Chandran

Reputation: 24791

Can you try doing so:

<category name="com.myPackage.src">
      <priority value="DEBUG"/>
   </category>

Upvotes: 0

Related Questions