Setting up Log4j in JBoss
I have been working with Jboss for the last 10 months and one thing I have never really looked at was using Log4j or Commons-Logging in my source code. I have always used println statements. So, yesterday after trying to port some external, stand-alone applications to the JBoss server—applications that already have Log4j and Commons-Logging statements in them—I decided to finally figure out how to set it all up.
It was actually easier then I thought it would be. However, I did run into more then a few comments about how hard it was. Anyway, boiled all down, here is the link that I used to set everything up.
Log4j in JBoss — basically, you have to setup your logging to go through JBoss’ logging. And that is where the problem lies. This intermixes your log statements with those of JBoss and renders your log4j.properties file almost useless.
In addition to everything stated in the link above, I had to add a custom section to the log4j.xml file in order to raise Hibernate’s logging to ERROR instead of INFO. Here is what I added:
<category name="net.sf.hibernate">
<priority value="ERROR"/>
</category>
Here is a post on the JBoss Wiki site about setting up Log4j.