[logback-user] Custom appender

Natan Cox natan.cox at tenforce.com
Tue Jul 13 11:50:49 CEST 2010


Class of appender should be
logback.eclipseappender.EclipseAppender

N

On Tue, Jul 13, 2010 at 11:20 AM, Frank Grimm <grimmfrank at googlemail.com>wrote:

> Dear mailing list,
>
> I'm trying to use logback (via its slf4j API) in an Eclipe/OSGi
> environment. More specifically I'm trying to write a logback appender that
> redirects log events to the Eclipse logging mechanism
> (org.eclipse.core.runtime.ILog).
>
> So the first thing I did was to create an Eclipse plugin/PDE project for
> the custom appender. In the project, the following class was added:
>
> package logback.eclipseappender;
>
> import ch.qos.logback.core.AppenderBase;
>
> public class EclipseAppender extends AppenderBase<Object> {
>        @Override
>        protected void append(Object eventObject) {
>                // TODO
>        }
> }
>
> The a logback configuration that made use of the custom appender was added
> to the project, too:
>
> <configuration>
>        <appender
>                name="eclipse"
>                class="eclipseappender.EclipseAppender">
>                <layout class="ch.qos.logback.classic.PatternLayout">
>                        <Pattern>%d %p %t %c - %m%n</Pattern>
>                </layout>
>        </appender>
>
>        <root level="debug">
>                <appender-ref ref="eclipse"/>
>        </root>
> </configuration>
>
> When the custom appender plugin/bundle is started in a new Eclipse runtime
> environment, the appender's class cannot be found (see stacktrace below).
>
> I've read in another post (DynamicClassLoadingException - How does class
> loading in logback works?) that logback might require the logback jar files
> and the custom appender jar file to be bundled together. But bundling them
> does not make sense in OSGi environments since single bundles for each of
> logback's components (core, classic, slf4j API) and custom appenders should
> be used.
>
> Is there a way to make logback see the appender class event if it's in
> another jar/bundle?
>
> Thanks,
> Frank
>
> 11:00:58,210 |-INFO in ch.qos.logback.core.joran.action.AppenderAction -
> About to instantiate appender of type [eclipseappender.EclipseAppender]
> 11:00:58,211 |-ERROR in ch.qos.logback.core.joran.action.AppenderAction -
> Could not create an Appender of type [eclipseappender.EclipseAppender].
> ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate
> type eclipseappender.EclipseAppender
>        at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to
> instantiate type eclipseappender.EclipseAppender
>        at      at
> ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:53)
>
> [...]
>
> Caused by: java.lang.ClassNotFoundException:
> eclipseappender.EclipseAppender
>        at      at
> org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
>        at      at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
>        at      at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
>        at      at
> org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
>        at      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>        at      at
> ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:45)
>        at      ... 52 common frames omitted
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20100713/35d15c02/attachment.html>


More information about the Logback-user mailing list