diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/selector/ContextJNDISelector.java b/logback-classic/src/main/java/ch/qos/logback/classic/selector/ContextJNDISelector.java index 546074e..aa1cce1 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/selector/ContextJNDISelector.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/selector/ContextJNDISelector.java @@ -27,10 +27,14 @@ import javax.naming.Context; import javax.naming.NamingException; import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.gaffer.GafferConfigurator; +import ch.qos.logback.classic.gaffer.GafferUtil; import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.classic.util.ContextInitializer; +import ch.qos.logback.classic.util.EnvUtil; import ch.qos.logback.classic.util.JNDIUtil; import ch.qos.logback.core.joran.spi.JoranException; +import ch.qos.logback.core.status.ErrorStatus; import ch.qos.logback.core.status.InfoStatus; import ch.qos.logback.core.status.StatusManager; import ch.qos.logback.core.status.WarnStatus; @@ -154,12 +158,25 @@ public class ContextJNDISelector implements ContextSelector { } private void configureLoggerContextByURL(LoggerContext context, URL url) { + if (url.toString().endsWith("groovy")) { + if (EnvUtil.isGroovyAvailable()) { + // avoid directly referring to GafferConfigurator so as to avoid + // loading groovy.lang.GroovyObject . See also http://jira.qos.ch/browse/LBCLASSIC-214 + GafferUtil.runGafferConfiguratorOn(context, this, url); + } else { + StatusManager sm = context.getStatusManager(); + sm.add(new ErrorStatus("Groovy classes are not available on the class path. ABORTING INITIALIZATION.", + context)); + } + } + if (url.toString().endsWith("xml")) { try { JoranConfigurator configurator = new JoranConfigurator(); context.reset(); configurator.setContext(context); configurator.doConfigure(url); } catch (JoranException e) { + } } StatusPrinter.printInCaseOfErrorsOrWarnings(context); }