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!
lol take heart, he wrote it in ” This entry was posted on Saturday, July 31st, 2004 “, it probably worked back then 😉
I think that this doesn’t work with Jboss 4 😉