Any chances that you would accept a pull request providing a solution to make Logback and Janino work together in an OSGi environment?

Hello, As stated in http://logback.qos.ch/setup.html conditional processing in configuration files requires the Janino library. When running in an OSGi environment (e.g. an Eclipse RCP application) simply placing commons-compiler.jar and janino.jar on your application's class path is not sufficient enough. You will get the following exception: <...> 12:50:47,754 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG 12:50:47,755 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [stdout] to Logger[ROOT] 12:50:47,755 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file] to Logger[ROOT] 12:50:47,810 |-ERROR in ch.qos.logback.core.joran.conditional.IfAction - Failed to parse condition [property("xxx.instance").equals("SIM_LOCAL")] org.codehaus.janino.JaninoRuntimeException: Cannot load class 'ch.qos.logback.core.joran.conditional.PropertyWrapperForScripts' through the parent loader at org.codehaus.janino.JaninoRuntimeException: Cannot load class 'ch.qos.logback.core.joran.conditional.PropertyWrapperForScripts' through the parent loader at at org.codehaus.janino.SimpleCompiler$1.getDelegate(SimpleCompiler.java:306) at at org.codehaus.janino.SimpleCompiler$1.accept(SimpleCompiler.java:291) at at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:5159) at at org.codehaus.janino.UnitCompiler.access$16700(UnitCompiler.java:185) at at org.codehaus.janino.UnitCompiler$29.getSuperclass2(UnitCompiler.java:8154) at at org.codehaus.janino.IClass.getSuperclass(IClass.java:406) at at org.codehaus.janino.IClass.getIMethods(IClass.java:223) at at org.codehaus.janino.IClass.getIMethods(IClass.java:199) at at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:409) at at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:393) at at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:185) at at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:347) at at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1139) at at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:354) at at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:322) at at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:383) at at org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:315) at at org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:233) at at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:192) at at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:84) at at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:77) at at ch.qos.logback.core.joran.conditional.PropertyEvalScriptBuilder.build(PropertyEvalScriptBuilder.java:51) at at ch.qos.logback.core.joran.conditional.IfAction.begin(IfAction.java:67) at at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:275) at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:147) at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:129) at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:149) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:135) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49) at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:77) at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:152) at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85) at at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55) at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:141) at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120) at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331) at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283) at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304) at at com.xxx.yyy.client.ui.lifecycle.StartHandler.<init>(StartHandler.java:22) at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at at org.eclipse.e4.core.internal.di.ConstructorRequestor.execute(ConstructorRequestor.java:42) at at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:343) at at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:264) at at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162) at at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:104) at at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:73) at at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:55) at at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:235) at at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:145) at at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380) at at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235) at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at at java.lang.reflect.Method.invoke(Method.java:497) at at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669) at at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608) at at org.eclipse.equinox.launcher.Main.run(Main.java:1515) at at org.eclipse.equinox.launcher.Main.main(Main.java:1488) 12:50:47,811 |-ERROR in ch.qos.logback.core.joran.conditional.IfAction - Failed to determine "if then else" result 12:50:47,811 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. <...> This exception occurs because in an OSGi environment the class loader of the org.cohehaus.janino bundle can not load classes from the ch.qos.logback.core bundle. See http://moi.vonos.net/java/osgi-classloaders/ and http://nstouchstones.blogspot.co.at/2010/07/class-loader-architecture-compar... for a primer on OSGi class loading. The org.cohehaus.janino bundle would need a "Require-Bundle: ch.qos.logback.core" directive in it's manifest file in order for the bundle class loader to be able to load classes from the ch.qos.logback.core bundle. This can be achieved by extending the org.cohehaus.janino bundle via a fragment (e.g. ch.qos.logback.core.janino.fragment). Below is the manifest of the fragment: Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Janino Fragment (needed to uses Janino together with logback in an OSGi environment) Bundle-SymbolicName: ch.qos.logback.core.janino.fragment Bundle-Version: 1.0.0 Fragment-Host: org.cohehaus.janino Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: ch.qos.logback.core Bundle-Vendor: Danube Development I would like to ask if you would accept a pull request for https://github.com/qos-ch/logback-contrib or https://github.com/qos-ch/logback-extensions if I would prepare such a fragment (named e.g. ch.qos.logback.core.janino.fragment). - Chris
participants (1)
-
Christoph Zauner