5 Replies Latest reply on Dec 5, 2007 3:58 PM by stlecho

    Seperate log4j.xml for each application

    lost_traveller

      I have an application contained within an EAR file that uses Log4J for logging. I have a requirement to use the log4j.xml configuration file contained within the EAR. Is it possible to have additional log4j.xml files for each application?

      I have tried using an MBean within the EAR to do the following but this fails to work since it is already configured by jboss:

      org.apache.log4j.PropertyConfigurator.configure(log4jPropFile.toURL());


      Is the only way to configure each of your applications log4j loggers is to modify conf/log4j.xml in the server directory?

        • 1. Re: Seperate log4j.xml for each application
          • 2. Re: Seperate log4j.xml for each application
            bensonfungjava

            Hi,

            Both suggestion from the Wiki don't work. It is cheating.

            I just cut and paste the code into my code, it doesn't work at all.


            too bad

            Benson

            • 3. Re: Seperate log4j.xml for each application
              lost_traveller

              Yeah I couldn't get it to work either, allbeit I didn't try for very long.

              It seems to be a poor feature of Log4J that you can only have one config per JVM. In the end we have to have 1 log4j config in our EAR file which has knowledge of every application deployed and the JBoss log4j config too, as you can understand this is not ideal.

              • 4. Re: Seperate log4j.xml for each application

                the problem is not comming log4j. It's a jboss classloading problem.
                In jboss4.3 sp1 version, you could have a log4j.jar version for each of you application.

                But with jboss 4.2 version doing so, you may experience with exception below

                log4j:ERROR A "org.jboss.logging.appender.FileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
                log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
                log4j:ERROR [WebappClassLoader
                 delegate: false
                 repositories:
                 /WEB-INF/classes/
                ----------> Parent Classloader:
                java.net.FactoryURLClassLoader@18c10af
                ] whereas object of type
                log4j:ERROR "org.jboss.logging.appender.FileAppender" was loaded by [org.jboss.system.server.NoAnnotationURLClassLoader@1a33d48].
                log4j:ERROR Could not instantiate appender named "FILE".
                


                It seem not possible to override jboss server librairies (log4j.jar is present in jboss server lib and has been customised).
                Even if you try to isolate classloadiing, it's not working witk log4j.
                Meissa

                • 5. Re: Seperate log4j.xml for each application
                  stlecho

                  After searching on the different forums, it seems that there is no clear solution to solve this issue. With the application we are developing, the same problem occurs.

                  We are deploying an app1.WAR and a app2.EAR file in JBoss. Each of them has its own log4j.xml and logging occurs respectively in app1.log and app2.log.

                  When JBoss is started, JBoss' default server.log file is used for the logging. When app1.WAR is "activated", app1.log is used but server.log is no longer used. When app2.EAR is "activated", app2.log is used but app1.log is no longer used. This behavior seems to be totally random.

                  Changing JBoss' default log4j.xml file solves the above described issue, but it remains a workaround and it surprises me that JBoss does not allow an application-specific logging configuration.

                  What are the guidelines that should be followed to allow separate logging for each application ?

                  Regards, Stefan Lecho.