Forum Home » Fuse Distributions » Fuse ESB

Thread: log4j extras

 
This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Feb 22, 2012 6:01 PM Last Post By: timgstewart
timgstewart

Posts: 22
Registered: 11/11/11
log4j extras
Posted: Feb 21, 2012 6:04 PM
 
  Click to reply to this thread Reply
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=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.out.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.out.rollingPolicy.FileNamePattern=/var/log/fuse/servicemix.esb-smx01.%d{yyyy-MM-dd}.gz
log4j.appender.out.rollingPolicy.ActiveFileName=/var/log/fuse/servicemix.esb-smx01.log
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j.appender.out.append=true

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 http://org.apache.log4j.rolling.RollingFileAppender.
java.lang.ClassNotFoundException: org.apache.log4j.rolling.RollingFileAppender not found by org.ops4j.pax.logging.pax-logging-service [3]
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?

timgstewart

Posts: 22
Registered: 11/11/11
Re: log4j extras
Posted: Feb 21, 2012 6:47 PM   in response to: timgstewart in response to: timgstewart
 
  Click to reply to this thread Reply
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):

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.6</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.apache.log4j.extras;version=1.1,
org.apache.log4j.filter;version=1.1,
org.apache.log4j.rolling;version=1.1,
org.apache.log4j.rule;version=1.1</Export-Package>
<Import-Package>!*</Import-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=true</Embed-Dependency>
<Fragment-Host>org.ops4j.pax.logging.pax-logging-service</Fragment-Host>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.1</version>
</dependency>
</dependencies>

timgstewart

Posts: 22
Registered: 11/11/11
Re: log4j extras
Posted: Feb 21, 2012 6:57 PM   in response to: timgstewart in response to: timgstewart
 
  Click to reply to this thread Reply
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?

ffang

Posts: 1,320
Registered: 12/24/07
Re: log4j extras
Posted: Feb 22, 2012 1:04 AM   in response to: timgstewart in response to: timgstewart
 
  Click to reply to this thread Reply
Hi,

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 ${FUSE_ESB}/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 ${FUSE_ESB}/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.

Freeman
timgstewart

Posts: 22
Registered: 11/11/11
Re: log4j extras
Posted: Feb 22, 2012 6:01 PM   in response to: ffang in response to: ffang
 
  Click to reply to this thread Reply
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.