4 Replies Latest reply on Feb 22, 2012 1:01 PM by Timothy Stewart

    log4j extras

    Timothy Stewart Newbie

      Hopefully this is a nice easy question.


      I want to use the log4j-extras-1.1.jar file from Log4j companions to make use of the time based rollover and auto-gzipping features in the org.apache.log4j.rolling.RollingFileAppender.


      I updated my org.ops4j.paxlogging.cfg to use this appender:


      1. File appender






      log4j.appender.out.layout.ConversionPattern=%d | %-5.5p | %-16.16t | %-32.32c | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n



      However, the class for the appender cannot be found as the extras are not included in the pax logging bundle.  It appears that it embeds the log4j classes within the bundle jar.


      I tried to put the log4j-extras-1.1.jar file from apache (which is an osgi bundle as well) in the various sub-folders under /lib as well as in the /system folder following the maven structure.


      All attempts resulting in a NoClassDef found on startup when the logging tries to configure:



      log4j:ERROR Could not instantiate class .

      java.lang.ClassNotFoundException: org.apache.log4j.rolling.RollingFileAppender not found by org.ops4j.pax.logging.pax-logging-service

              at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:812)

              at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:72)

              at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1806)

              at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

              at java.lang.Class.forName0(Native Method)

              at java.lang.Class.forName(Class.java:169)

              at org.apache.log4j.helpers.Loader.loadClass(Loader.java:198)

              at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:326)

              at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:123)

              at org.apache.log4j.PaxLoggingConfigurator.parseAppender(PaxLoggingConfigurator.java:81)

              at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)

              at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615)

              at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502)

              at org.apache.log4j.PaxLoggingConfigurator.doConfigure(PaxLoggingConfigurator.java:57)

              at org.ops4j.pax.logging.service.internal.PaxLoggingServiceImpl.updated(PaxLoggingServiceImpl.java:187)

              at org.ops4j.pax.logging.service.internal.PaxLoggingServiceImpl$1ManagedPaxLoggingService.updated(PaxLoggingServiceImpl.java:321)

              at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1195)

              at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:105)

              at java.lang.Thread.run(Thread.java:662)

      log4j:ERROR Could not instantiate appender named "out".



      What can I do to make Fuse and pax-logging find this class?

        • 1. Re: log4j extras
          Timothy Stewart Newbie

          Okay, I think I'm on the trail... I've created a project with a pom.xml that depends on the apache-log4j-extras, and in the bundle instructions embeds it into the bundle.  It then sets the Fragment-Host to be org.ops4j.pax.logging.pax-logging-service.


          I put this bundle in my system folder, and added it to startup.properties just before the logging api and logging service.


          I thought this would work, but it is still not working.  I know it is finding my bundle, because if I put some bad spelling in the startup.properties it complains about not finding the bundle.


          I don't see my bundle in osgi:list.  Should fragments show up?


          Is there something more I need to do to get a fragment to attach to the logging service?  Do I need to osgi:install system bundles?



          FYI, my pom is as follows (snipping off the top part):




          • 2. Re: log4j extras
            Timothy Stewart Newbie

            Okay, I got it working.  I had to do:



            install file:system/com/dmotorworks/vehicleinventory/dse/dse-logging-extras/1.0.0-SNAPSHOT/dse-logging-extras-1.0.0-SNAPSHOT.jar



            It feels dirty though.  Is there a cleaner way to do what I've done?

            • 3. Re: log4j extras
              Freeman(Yue) Fang Master



              Basically yes you must put customer appender in a fragment bundle and attach it to org.ops4j.pax.logging.pax-logging-service bundle.


              If you want to your fragment bundle get installed  before org.ops4j.pax.logging.pax-logging-service bundle, you can copy the new appender fragment into the $/system directory. FUSE ESB uses a virtual maven repository to access resources in the system directory, so the jar path should use the standard maven groupId/artifactId/version/ convention, where the groupId is a directory structure. Edit $/etc/startup.properties and add the new fragment bundle to the list before the pax-logging-service bundle.

              Restart Fuse ESB with a clean run(remove FUSE_ESB/data folder) to reload the system bundles, and now you can use the appender in your log4j config.



              • 4. Re: log4j extras
                Timothy Stewart Newbie

                Thanks very much.  This is exactly what I did, though I didn't realize the auto-activation of system bundles on initial startup.


                Appreciate the feedback.