I want to turn up the logging level on JBoss so that I can verify that the transactional AOP advice runs before the Spring-security-context-populatin’ advice. The reason being, I want to make sure we’re already in a transaction if something goes wrong in the security context advice, so the message will get rolled back onto the queue.
To be more precise, I want to turn up the logging level on the right categories of classes — my server/default/log/server.log is already 190MB today, and Notepad and Eclipse are having trouble opening it.
The Packages I want to log about
For the first round, I want to see DEBUG-level messages for my Spring-security-context-populatin’ advice (the com.ontsys.advice package in my prototype) and the org.springframework.transaction.jta package.
Adding Logging to my Class
First, I need to add logging to my class — it currently doesn’t log any messages.
Adding logging to a class is simple:
import org.apache.log4j.Logger;
public class MyClass {
private static final Logger LOGGER = Logger.getLogger(MyClass.class);
public void decombobulate() {
LOGGER.debug("Decombobulating...");
//...
}
}
Configuring jboss-log4j.xml
The Logging Conventions chapter of the JBoss Development Process Guide (see also the Logging page on the JBoss Wiki) explains how to log certain categories to a different file.
Only instead of ${jboss.server.home.dir}/log/ I’ll use more elegant ${jboss.server.log.dir}/ .
Everything in its Proper Place
Note that according to the log4j 1.2.15 DTD, the elements have to be ordered with all appenders first, followed by categories, and then the root element:
<!ELEMENT log4j:configuration (renderer*, appender*,plugin*, (category|logger)*,root?,
(categoryFactory|loggerFactory)?)>
Additivity
Note also that there is an additivity attribute you can use on the on the appenders. The section called Redirecting Category Output has this to say about the additivity attribute:
The additivity attribute controls whether output continues to go to the root category appender. If false, output only goes to the appenders referred to by the category.
That would explain why my main server/default/log/server.log was so small the other time I tried adding a category appender — I think I had additivity=”false” from an example configuration I found somewhere, without understanding what it meant — so output that was going to my special log file was no longer going to my server.log file.
The DTD says that the additivity attribute defaults to “true” though, which is what I want, so I’m leaving it out.
My Changes to jboss-log4j.xml
Here’s what I eventually came up with:
<appender name="AdviceLog" class="org.apache.log4j.FileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler" />
<param name="Append" value="false" />
<param name="File" value="${jboss.server.log.dir}/advice.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n" />
</layout>
</appender>
...
<category name="com.ontsys.advice">
<priority value="DEBUG" />
<appender-ref ref="AdviceLog" />
</category>
<category name="org.springframework.transaction.jta">
<priority value="DEBUG" />
<appender-ref ref="AdviceLog" />
</category>
Success
This worked great! Only stuff from the com.ontsys.advice and org.springframework.transaction.jta packages in the advice.log, at the DEBUG level.
For Next Time
At first the advice.log file was getting way too much information… but we’ll stop here for the moment!