diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull.java b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull.java index 37043c3e6a..90a4c50340 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull.java @@ -48,7 +48,7 @@ static public ModelHandlerBase makeInstance2(Context context, ModelInterpretatio } @Override - protected void processScanAttrib( ModelInterpretationContext mic, ConfigurationModel configurationModel) { + protected void processScanAttrib(ModelInterpretationContext mic, ConfigurationModel configurationModel) { } @@ -60,8 +60,22 @@ public void postHandle(ModelInterpretationContext mic, Model model) throws Model protected void postProcessScanAttrib(ModelInterpretationContext mic, ConfigurationModel configurationModel) { String scanStr = mic.subst(configurationModel.getScanStr()); - if (!OptionHelper.isNullOrEmptyOrAllSpaces(scanStr) && !"false".equalsIgnoreCase(scanStr)) { + String scanPeriodStr = mic.subst(configurationModel.getScanPeriodStr()); + detachedPostProcess(scanStr, scanPeriodStr); + } + /** + * This method is called from this class but also from logback-tyler. + * + * This method assumes that the variables scanStr and scanPeriodStr have undergone variable substitution + * as applicable to their current environment + * + * @param scanStr + * @param scanPeriodStr + * @since 1.5.0 + */ + public void detachedPostProcess(String scanStr, String scanPeriodStr) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(scanStr) && !"false".equalsIgnoreCase(scanStr)) { ScheduledExecutorService scheduledExecutorService = context.getScheduledExecutorService(); boolean watchPredicateFulfilled = ConfigurationWatchListUtil.watchPredicateFulfilled(context); if (!watchPredicateFulfilled) { @@ -76,7 +90,6 @@ protected void postProcessScanAttrib(ModelInterpretationContext mic, Configurati context.fireConfigurationEvent(ConfigurationEvent.newConfigurationChangeDetectorRegisteredEvent(rocTask)); - String scanPeriodStr = mic.subst(configurationModel.getScanPeriodStr()); Duration duration = getDurationOfScanPeriodAttribute(scanPeriodStr, SCAN_PERIOD_DEFAULT); addInfo("Will scan for changes in [" + ConfigurationWatchListUtil.getConfigurationWatchList(context) + "] "); @@ -91,6 +104,7 @@ protected void postProcessScanAttrib(ModelInterpretationContext mic, Configurati rocTask.setScheduredFuture(scheduledFuture); context.addScheduledFuture(scheduledFuture); } + } private Duration getDurationOfScanPeriodAttribute(String scanPeriodAttrib, Duration defaultDuration) { diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/PropertiesConfiguratorModelHandler.java b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/PropertiesConfiguratorModelHandler.java index 27cb776729..ef6c717aec 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/PropertiesConfiguratorModelHandler.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/PropertiesConfiguratorModelHandler.java @@ -24,6 +24,7 @@ import ch.qos.logback.core.model.processor.ModelHandlerException; import ch.qos.logback.core.model.processor.ModelInterpretationContext; import ch.qos.logback.core.model.processor.ResourceHandlerBase; +import ch.qos.logback.core.spi.ContextAwarePropertyContainer; import ch.qos.logback.core.util.OptionHelper; import java.io.InputStream; @@ -44,6 +45,21 @@ static public PropertiesConfiguratorModelHandler makeInstance(Context context, M @Override public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException { + detachedHandle(mic, model); + } + + /** + * + * Used by {@link #handle(ModelInterpretationContext, Model)} as well as logback-tyler. Note the widening of the + * base from {@link ModelInterpretationContext} to {@link ContextAwarePropertyContainer}. + * + * @param capc + * @param model + * @throws ModelHandlerException + * @since 1.5.10 + */ + public void detachedHandle(ContextAwarePropertyContainer capc, Model model) throws ModelHandlerException { + PropertiesConfiguratorModel propertyConfiguratorModel = (PropertiesConfiguratorModel) model; this.optional = OptionHelper.toBoolean(propertyConfiguratorModel.getOptional(), false); @@ -53,27 +69,27 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand return; } - InputStream in = getInputStream(mic, propertyConfiguratorModel); - if(in == null) { + InputStream in = getInputStream(capc, propertyConfiguratorModel); + if (in == null) { inError = true; return; } - addInfo("Reading configuration from ["+getAttribureInUse()+"]"); + addInfo("Reading configuration from [" + getAttribureInUse() + "]"); PropertiesConfigurator propertiesConfigurator = new PropertiesConfigurator(); - propertiesConfigurator.setContext(mic.getContext()); + propertiesConfigurator.setContext(capc.getContext()); try { propertiesConfigurator.doConfigure(in); } catch (JoranException e) { - addError("Could not configure from "+getAttribureInUse()); + addError("Could not configure from " + getAttribureInUse()); throw new ModelHandlerException(e); } } - protected InputStream getInputStream(ModelInterpretationContext mic, ResourceModel resourceModel) { - URL inputURL = getInputURL(mic, resourceModel); + protected InputStream getInputStream(ContextAwarePropertyContainer capc, ResourceModel resourceModel) { + URL inputURL = getInputURL(capc, resourceModel); if (inputURL == null) return null; diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/ResourceHandlerBase.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/ResourceHandlerBase.java index 85fdb74f4d..d6c3ea03e4 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/ResourceHandlerBase.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/ResourceHandlerBase.java @@ -16,6 +16,7 @@ import ch.qos.logback.core.Context; import ch.qos.logback.core.model.ResourceModel; +import ch.qos.logback.core.spi.ContextAwarePropertyContainer; import ch.qos.logback.core.util.Loader; import ch.qos.logback.core.util.OptionHelper; @@ -78,23 +79,23 @@ protected String getAttribureInUse() { return this.attributeInUse; } - protected URL getInputURL(ModelInterpretationContext mic, ResourceModel resourceModel) { + protected URL getInputURL(ContextAwarePropertyContainer contextAwarePropertyContainer, ResourceModel resourceModel) { String fileAttribute = resourceModel.getFile(); String urlAttribute = resourceModel.getUrl(); String resourceAttribute = resourceModel.getResource(); if (!OptionHelper.isNullOrEmptyOrAllSpaces(fileAttribute)) { - this.attributeInUse = mic.subst(fileAttribute); + this.attributeInUse = contextAwarePropertyContainer.subst(fileAttribute); return filePathAsURL(attributeInUse); } if (!OptionHelper.isNullOrEmptyOrAllSpaces(urlAttribute)) { - this.attributeInUse = mic.subst(urlAttribute); + this.attributeInUse = contextAwarePropertyContainer.subst(urlAttribute); return attributeToURL(attributeInUse); } if (!OptionHelper.isNullOrEmptyOrAllSpaces(resourceAttribute)) { - this.attributeInUse = mic.subst(resourceAttribute); + this.attributeInUse = contextAwarePropertyContainer.subst(resourceAttribute); return resourceAsURL(attributeInUse); } // given preceding checkAttributes() check we cannot reach this line