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"/>

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"/>

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.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!

About Author

AMIS employee


  1. Pingback: Air Force One Shoes

  2. Pingback: Hdtvs For Less

  3. Pingback: Tshirt

  4. Pingback: Ford Truck Parts

  5. Pingback: Wireless Video Camera

  6. Pingback: Rear Projection Hdtvs

  7. Pingback: Tvs For Less

  8. lol take heart, he wrote it in ” This entry was posted on Saturday, July 31st, 2004 “, it probably worked back then 😉