Log4j in JBoss

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

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

9 thoughts on “Log4j in JBoss

  1. Pingback: Hdtvs For Less
  2. Pingback: Tshirt
  3. Pingback: Ford Truck Parts
  4. Pingback: Tvs For Less
  5. lol take heart, he wrote it in ” This entry was posted on Saturday, July 31st, 2004 “, it probably worked back then 😉

Comments are closed.

Next Post

Sequence beans: auto-increment of primary key fields

An auto-incremet of your primary key field whenever a new record is inserted, is a feature commonly found in many databases (e.g., the auto_increment of MySQL, the identity field in Hypersonic SQL or the sequence in Oracle). If you want such a feature for your entity beans, a sequence (generator) […]
%d bloggers like this: