[logback-user] Logback, OSGi and DynamicClassLoadingException

Benoît Thiébault thiebault at artenum.com
Mon Dec 3 11:34:48 CET 2012


Hi everyone,

I am migrating an OSGi-based application from System.out.println to slf4j / logback and I am having some problems.

I have provided logback with a configuration file via the "logback.configurationFile" and it works very well.

In this configuration file, I have defined a specific appender that I have developed, but logback fails to instantiate it (cf. stacktrace below).

This is not really a surprise: each OSGi bundle has its own classloader. My org.test.LogConsole is in its own bundle and thus logback classloader cannot find it.

One solution is to declare my org.test.LogConsole bundle as a fragment of logback. The fragment bundle is not a bundle per se and shares its classloader with the host bundle.

This is however very constraining in term of bundle resolution / starting order as the fragment bundle has to be installed before the host.

Isn't there another way (such as LogBack.Configuration.addClassloader()) to indicate logback classic where to search for my org.test.LogConsole class ?

Kind regards,

Ben


10:58:48,848 |-ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [org.test.LogConsole]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type org.test.LogConsole
	at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type org.test.LogConsole
	at 	at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:74)
	at 	at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:49)
	at 	at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:35)
	at 	at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:54)
	at 	at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:276)
	at 	at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:148)
	at 	at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:130)
	at 	at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:157)
	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:143)
	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:106)
	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:56)
	at 	at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
	at 	at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
	at 	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
	at 	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:54)
	at 	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
	at 	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
	at 	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
	at 	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
	
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20121203/50d189d5/attachment.html>


More information about the Logback-user mailing list