I'm using Karaf 2.2.5 and would like to add a custom log4j filter to Pax
logging. The background can be found at:

http://karaf.922171.n3.nabble.com/Logging-using-log4j-filters-tt3699528.html

I had discussion with Guillaume at the Karaf mailing list. In short, I had
misunderstood how the StringMatchFilter worked and realised that I need to
create my own custom filter in order to filter based on MDC information.

It turned out that the filter I need had been developed in log4j trunk in
preparation for log4j 1.3. However, the development of log4j 1.3 has
stopped (and will not be resumed AFAIU). I then copied the source code from
log4j in order to repackage it by myself and create a custom filter.

See "MDCMatchFilter" at:

http://wiki.apache.org/logging-log4j/Log4jv13Features

I think this is a filter that should be part of Pax logging (since it will
never be part of log4j). Can I create a JIRA for that or do you think it is
inappropriate to put it in Pax logging?

Regardless of that, I still would like to get my custom filter to work -
which did not turn out to be very easy.

I followed the guidelines in Karaf user manual. I created my filter bundle
(basically containing "stolen" log4j code for the MDCMatchFilter) as a
fragment with the host "org.ops4j.pax.logging.pax-logging-service".

On Karaf startup I get the following error on stdout:

*ERROR: Bundle org.ops4j.pax.logging.pax-logging-service [4] Error starting
mvn:org.ops4j.pax.logging/pax-logging-service/1.6.3
(org.osgi.framework.BundleException: Activator start error in bundle
org.ops4j.pax.logging.pax-logging-service
[4].)java.lang.NoClassDefFoundError: org/apache/log4j/PaxLoggingConfigurator
*
*        at
org.ops4j.pax.logging.service.internal.PaxLoggingServiceImpl.configureDefaults(PaxLoggingServiceImpl.java:251)
*
*        at
org.ops4j.pax.logging.service.internal.PaxLoggingServiceImpl.<init>(PaxLoggingServiceImpl.java:61)
*
*        at
org.ops4j.pax.logging.service.internal.Activator.start(Activator.java:108)*
*        at
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:629)
*
*        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1842)
*
*        at org.apache.felix.framework.Felix.startBundle(Felix.java:1759)*
*        at
org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1163)*
*        at
org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)*
*        at java.lang.Thread.run(Thread.java:662)*
*Caused by: java.lang.ClassNotFoundException:
org.apache.log4j.PaxLoggingConfigurator not found by
org.ops4j.pax.logging.pax-logging-api [5]*
*        at
org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
*
*        at
org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)*
*        at
org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)
*
*        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)*
*        at
org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:645)
*
*        at
org.apache.felix.framework.resolver.WireImpl.getClass(WireImpl.java:99)*
*        at
org.apache.felix.framework.ModuleImpl.searchImports(ModuleImpl.java:1390)*
*        at
org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:722)
*
*        at
org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)*
*        at
org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)
*
*        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)*
*        ... 9 more*

It indicates (I think) that the pax api bundle (bundle 5) cannot find the
PaxLoggingConfigurator class which resides in the package org.apache.log4j
package which in turn is contained both within the pax api bundle and the
pax service bundle. It is also exported by the pax api bundle (and imported
by the pax service bundle). I think this is really strange since it seems
to be the version in pax api that has been resolved and imported into pax
service. Why then cant't pax api find its own class?

I have a feeling that I'm entering the tricky parts of OSGi here with
copies of classes (packages) in multiple bundles in combination with "uses"
constraints...

I appreciate any advice as to how this is solved. I assume I'm not the
first developer to create a custom filter for Pax logging (but you never
know).

/Bengt
_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to