1

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

user265330
  • 2,533
  • 6
  • 31
  • 42
  • so does everything work if you don't put anything in, but just use log4j appenders that were commented out? can you hilight or show the differences in the commented out appenders and your appender? – eis May 02 '13 at 14:39
  • Hi. I can see everything I would expect to see in server.log. However, I need to use log4j appenders (as I have my own appenders that have extra functionality). In deploy/jboss-logging all log4j-appender definitions are commented out. But the fact they were in there at all gave me hope that I should be able to add my log4j appender and it would be used by jboss logging's log4j bridge. – user265330 May 02 '13 at 14:58
  • I'm not sure if you read my comment in detail. I asked what would happen if you use log4j appenders that were commented out. But basically you don't want to use log4j appenders, but your own custom appenders, and that is the issue. In that case, you'd need to deploy them into the root class path I guess... – eis May 02 '13 at 16:01
  • Sorry, I missed your point there. None of the already-present commented out log4j appenders in jboss-logging.xml are overly useful to me. The list comprises: SMTP, SYSLOG, JMS, JMX, and TRAP_LOG. I tried uncommenting SYSLOG but got nothing in /var/log/messages. The class of the appender in my example is a standard log4j appender. I am just using that one to try to get my configuration right and see it being used. I will actually be using my own class (that extends org.apache.log4j.AppenderSkeleton, but that's not relevant here as I'm just trying to use a plain old RollingFileAppender here). – user265330 May 02 '13 at 17:15

1 Answers1

1

In order to use your own log4j.xml in case your application's log4j.jar is not kept inside EAR or WAR, you have to do following things.

  1. set environment variable : -Dlog4j.configuration=log4j.xml
  2. you have to comment given line in <jboss_home>\server\default\deployers\jboss-logging.deployer\META-INF\logmanager-jboss-beans.xml.

    <bean name="JBossLog4jRepostiorySelector" class="org.jboss.logmanager.log4j.BridgeRepositorySelector" />

Hope this will work for you

AlexB
  • 7,302
  • 12
  • 56
  • 74