I want to use log4j appenders in my JBoss 6.1 deployment. As I was having trouble getting this to work, I wrote some test code and noted that org.apache.log4j.Logger.getLogger(String) is returning an object of type org.jboss.logmanager.log4j.BridgeLogger.
So I figured I had two options: (1) try to get the getLogger call to return an apache log4j type rather than the JBoss BridgeLogger, or (2) accept that JBoss is doing some sort of bridging and get it to use the log4j appenders I have written that I need it to use.
So trying the first of those options: Logger.getLogger() delegates to LogManager.getLogger(String), which does:
return getLoggerRepository().getLogger(String);
The RepositorySelector is static in LogManager and is set up like this:
Hierarchy h = new Hierarchy(new RootLogger((Level) Level.DEBUG));
repositorySelector = new DefaultRepositorySelector(h);
but LogManager has a setRepositorySelector, so the conclusion I came to was that something in the JBoss startup process was calling setRepositorySelector. So to test that I called setRepositorySelector from my test logging code (setting it ti a DefaultRepositorySelector as the static initializer of LogManager does), and then checked what type of Logger is returned - and it's still of type org.jboss.logmanager.log4j.BridgeLogger!!
So now moving on to my second option: All I want is to be able to use log4j appenders - the deploy/jboss-logging.xml file has a lot of commented out log4j appenders, so they must be supported I guess. Therefore I put one in as follows:
<log4j-appender name="MYTEMPFILE" class="org.apache.log4j.RollingFileAppender">
<error-manager>
<only-once/>
</error-manager>
<level name="DEBUG"/>
<properties>
<property name="file">${jboss.server.home.dir}/log/serverx.log</property>
<property name="maximumFileSize">20480000</property>
<property name="maxBackupIndex">5</property>
</properties>
<formatter>
<pattern-formatter pattern="%d %-5p [%c] (%t) %m%n"/>
</formatter>
</log4j-appender>
<!-- tried this too
<logger category="com.myco">
<level name="DEBUG"/>
<handlers>
<handler-ref name="MYTEMPFILE"/>
</handlers>
</logger>
-->
...
<root-logger>
<!-- Set the root logger priority via a system property, with a default value. -->
<level name="${jboss.server.log.threshold:DEBUG}"/>
<handlers>
<handler-ref name="MYTEMPFILE"/>
<handler-ref name="CONSOLE"/>
<handler-ref name="FILE"/>
</handlers>
</root-logger>
With that change, not only do I not get my serverx.log file, I do not get anything written to server.log (server.log is populated without the above change).
I have read a lot about jboss-deployment-structure.xml and excluding log4j dependencies but I do not understand enough about what is being discussed to know if it is relevant to my issue. I suspect it is not relevant.
I even tried deploying this patch that sounded relevant: https://issues.jboss.org/browse/JBAS-8791 but no difference.
Anyone?
Thanks, Paul