Log4j in JBoss javacode 9085791

Log4j in JBoss

How do I enable logging under JBoss?

The configuration file log4j.xml resides in JBOSS_HOME/server/${your.server.configuration}/conf.

Let’s say that we want to enable logging in the console.
Look for the <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> section in the log4j.xml file. Change the level (I have changed it to DEBUG below) and the pattern (if you want to, I did it below and commented out the original one):

<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] Messagen -->
         <!--
         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
         -->
         <param name="ConversionPattern" value="%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L)  -%m%n"/>
      </layout>
</appender>

With this configuration, your debug messages will show up in the console as follows:

DEBUG 31-07 00:07:33,780 (SessionFacadeBean.java:deleteArticle:117)  -Deleting article, publication ID=Puk2003

Make sure to limit the output generated by JBoss itself now, otherwise you will have a hard time finding your own log messages 😉
You do this by uncommenting

<category name="org.jboss">
     <priority value="INFO"/>
     </priority>
</category>

from the “limit categories” section of the log4j.xml.

Finally, to get rid of the error messages that

log4j:ERROR Failed to create directory structure: /log
log4j:ERROR setFile(null,false) call failed.
java.io.FileNotFoundException: /log/boot.log (No such file or directory)

add a log4j.properties to your WEB-INF/classes as follows:

log4j.rootLogger=CONSOLE, stdout
log4j.logger.your.package.name=DEBUG
log4j.logger.xdoclet=INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L)  -%m%n

Replace your.package.name as appropriate.

Note the limiting of xdoclet, I had to include this in my development environment (Eclipse), otherwise the generation of the deployment descriptors and interface classes by Xdoclet would take forever due to the flood of log messages!

2 Comments

  1. Pingback: Air Force One Shoes April 27, 2007
  2. Pingback: Hdtvs For Less April 25, 2007
  3. Pingback: Tshirt April 24, 2007
  4. Pingback: Ford Truck Parts April 23, 2007
  5. Pingback: Wireless Video Camera April 21, 2007
  6. Pingback: Rear Projection Hdtvs April 20, 2007
  7. Pingback: Tvs For Less April 20, 2007
  8. John Seath March 28, 2007
  9. Diego Pires Plentz March 24, 2007