-
1. Re: Custom log4j Appender - activateOptions not called
bwallis42 Oct 4, 2011 7:34 PM (in response to bwallis42)To answer my own question...
The configuration I gave in the post above is not correct, the following works after a hack to the log4j adapter...
{code}
<log4j-appender name="UDRFILE" class="au.com.infomedix.log.appender.Log4jDatedRollingLogFileAppender">
<properties>
<property name="name">UDRFILE</property>
<property name="file">${web.app.data}/log/${jboss.server.name}.log</property>
<property name="maxFileSize">50mb</property>
<property name="maxLogFilePerDay">1000</property>
<property name="append">true</property>
<property name="pattern">%d %r %-5p [%t] %c{2} - %m%n</property>
</properties>
<error-manager>
<only-once />
</error-manager>
</log4j-appender>
{code}
Note that
- The appender name has to be in two places, as an attribute of the log4j-appender element and as a property. This is necessary as the attribute value in the log4j-adapter element is NOT passed through to the log4j appender via it's setName() method, properties are.
- The <formatter> element has been removed and a pattern property has been added using standard log4j pattern syntax. The formatter element did not setup the log4j appender's layout value (AppenderSkeleton.setLayout).
- I suspect the <error-manager> element does nothing for the log4j adapter but I haven't looked so I left it there, it doesn't break it at least.
The changes I had to make to the log4j adapter are:
- I call LogLog.setQuietMode(true) in my constructor as LogLog.debug() et.al. calls seem to call back into the logging framework as they are writing to STDERR and STDOUT which are redirected to the jboss logs.
- I had to add a setPattern() method that creates a Layout object and then calls setLayout with it.
- I overrode the append method to check if the adapter had been initialised yet and call the activeateOptions() method if not.
Now I have a working log4j adapter configured from jboss-logging.xml.
I do hope all of this has been fixed/rewritten in jboss AS7!