Log4j in JBoss

9

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):

&lt;appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"&gt;
      &lt;errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/&gt;
      &lt;param name="Target" value="System.out"/&gt;
      &lt;param name="Threshold" value="DEBUG"/&gt;

      &lt;layout class="org.apache.log4j.PatternLayout"&gt;
         &lt;!-- The default pattern: Date Priority [Category] Messagen --&gt;
         &lt;!--
         &lt;param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/&gt;
         --&gt;
         &lt;param name="ConversionPattern" value="%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L)  -%m%n"/&gt;
      &lt;/layout&gt;
&lt;/appender&gt;

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

&lt;category name="org.jboss"&gt;
     &lt;priority value="INFO"/&gt;
     &lt;/priority&gt;
&lt;/category&gt;

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!

Share.

About Author

9 Comments

  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 ;)