2 Replies Latest reply on Apr 23, 2002 11:19 PM by Fusayuki Minamoto

    A non-JBoss log4j Instance

    Thomas Phan Newbie


      I'm using JBoss 3 RH (CVS), and an external Calatina 4.0.1

      I want my application (EAR) to use log4j, but I don't want to use the log4j instance that JBoss uses.

      I've WEB-INF/lib/log4j.jar my WAR file. Since I use an external Tomcat, log4j executes in a different JVM than JBoss, and it gives the expected output for the web part.

      For the EJB part, I'm not sure which log4j instance my application is using (maybe they are using the same static instance). If JBoss doesn't use log4j, I should write a MBean that calls org.apache.log4j.PropertyConfigurator.configure().

      Since JBoss uses log4j, where should I set log4j.properties for my application? I set:

      log4j.rootCategory=DEBUG, Console, Jms

      in my WAR file, and it works fine (both to the console locally, and to the JMS/MDB running on the JBoss JVM). Is it possible to use a different log4j.properties file for my application than the one JBoss is using? I want to make my application to have an option to deploy in a non-JBoss application server.

      Also, in my JBoss console, I've more messages than I expected to see (they appear only in log/server.log before). How may I fix this?

      01:50:50,479 INFO [Default] 30705 [AutoDeployer] INFO org.jboss.deployment.J2eeDeployer#Default - Deployed J2EE application: file:/var/jboss-all/build/output/jboss-3.0.0alpha/deploy/esb.ear
      01:50:56,171 INFO [Default] 36398 [RMI TCP Connection(6)-] DEBUG org.jboss.ejb.EntityContainer - METHOD HOME INVOKE jboss.j2ee:service=EJB,jndiName=ejb/User||findByPrimaryKey||[Ljava.lang.Object;@25e68a
      01:50:56,223 INFO [Default] 36450 [RMI TCP Connection(6)-] DEBUG org.jboss.tm.TxCapsule User - Created new instance for tx=XidImpl [FormatId=257, GlobalId=//0, BranchQual=]
      01:50:56,224 INFO [Default] 36451 [RMI TCP Connection(6)-] DEBUG org.jboss.tm.TxManager User - began tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=//0, BranchQual=]
      01:50:56,331 INFO [Default] 36558 [RMI TCP Connection(6)-] DEBUG org.jboss.tm.TxCapsule User - registerSynchronization(): Entered, tx=XidImpl [FormatId=257, GlobalId=//0, BranchQual=] status=STATUS_ACTIVE
      01:50:56,332 INFO [Default] 36559 [RMI TCP Connection(6)-] DEBUG org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.User.findByPrimaryKey User - Executing SQL: SELECT ... FROM User WHERE username=?
      01:50:56,363 INFO [Default] 36589 [RMI TCP Connection(6)-] DEBUG org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.User.findByPrimaryKey User - Set parameter: index=1, jdbcType=VARCHAR, value=twhphan
      02:00:37,135 INFO [Default] 617362 [Minerva ObjectPool GC Thread] DEBUG org.jboss.pool.PoolGCThread - gc thread delay: 599999
      02:04:06,582 INFO [Default] 826809 [TimerTask Thread] DEBUG org.jboss.ejb.plugins.EnterpriseContextCachePolicy - Scheduling for passivation overaged bean User with id = [.twhphan.] - Cache size = 1
      02:04:06,583 INFO [Default] 826810 [TimerTask Thread] DEBUG org.jboss.ejb.plugins.EnterpriseContextCachePolicy - Aging out from cache bean Userwith id = [.twhphan.]; cache size = 1

      For above, it's possible that the JBoss JVM reads my log4j.properties file, as Jetty deploys my WAR file (as JBoss deploys my EAR file) as well

        • 1. Re: A non-JBoss log4j Instance
          Adrian Brock Master

          The short answer is you cannot do this.

          The first reason is that on a server configured
          with the J2ee spec's authorities your log4j.jar would
          not be able to retrieve the properties file.
          You would get a security exception/FilePermission.
          By default, JBoss does not install a security manager
          so you don't see this problem at the moment.

          The second reason is that if you share JBoss's log4j.jar
          doing a reconfigure would also reconfigure JBoss's

          IMHO logging configuration is not the job of the
          application, it is the job of the deployer using services
          available in application server.

          Having said I all that, I will "shortly" be doing some
          work that will allow you to do this.
          {Details omitted - it requires log4j 1.2 LoggerRepository}
          I'm also going to look at general logging configuration
          e.g. for apps that want to use java.util.logging in

          The preferred approach will be to specify the
          logging configuration/configurator in your deployment
          But it will also cater for applications that want
          to do it programitcally, assuming they are authorised.
          They will be authorised if they use the log4j in lib/ext

          The [Default] logging is a known problem. I will tidy
          this up before 3.0 goes final (probably before).


          • 2. Re: A non-JBoss log4j Instance
            Fusayuki Minamoto Apprentice


            > The second reason is that if you share JBoss's log4j.jar
            > doing a reconfigure would also reconfigure JBoss's
            > logging.

            I have your recommendations.
            But I just like to know why this happens.

            I looked at the Category.java in log4j 1.1.3 and found the static initializer for the default configuration.
            Thus I believe someone loads META-INF/lib/log4j.jar but don't make sure the timing of the load.

            I think that the jboss class loader already has log4j (by jboss.conf) and then the application class loader cannot find the local log4j because the application class loader looks for it using the parent class loader.

            Is jasper compilation related with this?
            Please explain how the local log4j is loaded.