From 4633df5853cd4afe17f8f61a3bab3a1d547e0c98 Mon Sep 17 00:00:00 2001 From: Ceki Gulcu Date: Wed, 9 Aug 2023 21:21:35 +0200 Subject: [PATCH] revert Configurator interface to match that in version 1.4.8 Signed-off-by: Ceki Gulcu --- .../qos/logback/classic/BasicConfigurator.java | 4 +--- .../joran/SerializedModelConfigurator.java | 3 ++- .../ch/qos/logback/classic/spi/Configurator.java | 16 +++++++++------- .../logback/classic/util/ContextInitializer.java | 2 +- .../classic/util/DefaultJoranConfigurator.java | 3 ++- .../logback/classic/util/MockConfigurator.java | 3 ++- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/BasicConfigurator.java b/logback-classic/src/main/java/ch/qos/logback/classic/BasicConfigurator.java index 0515dd0077..7bacb70c57 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/BasicConfigurator.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/BasicConfigurator.java @@ -35,11 +35,9 @@ public class BasicConfigurator extends ContextAwareBase implements Configurator public BasicConfigurator() { } - public ExecutionStatus configure(Context context) { + public ExecutionStatus configure(LoggerContext loggerContext) { addInfo("Setting up default configuration."); - LoggerContext loggerContext = (LoggerContext) context; - ConsoleAppender ca = new ConsoleAppender(); ca.setContext(context); ca.setName("console"); diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/joran/SerializedModelConfigurator.java b/logback-classic/src/main/java/ch/qos/logback/classic/joran/SerializedModelConfigurator.java index f3e6ba1b2d..9bf7c03f16 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/joran/SerializedModelConfigurator.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/joran/SerializedModelConfigurator.java @@ -15,6 +15,7 @@ package ch.qos.logback.classic.joran; import ch.qos.logback.classic.ClassicConstants; +import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.serializedModel.HardenedModelInputStream; import ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules; import ch.qos.logback.classic.spi.ConfiguratorRank; @@ -53,7 +54,7 @@ public class SerializedModelConfigurator extends ContextAwareBase implements Con protected ModelInterpretationContext modelInterpretationContext; @Override - public ExecutionStatus configure(Context context) { + public ExecutionStatus configure(LoggerContext loggerContext) { URL url = performMultiStepModelFileSearch(true); if (url != null) { diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/Configurator.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/Configurator.java index 7c5528624b..bd2c2e145e 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/Configurator.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/Configurator.java @@ -13,6 +13,7 @@ */ package ch.qos.logback.classic.spi; +import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.core.Context; import ch.qos.logback.core.spi.ContextAware; @@ -24,10 +25,10 @@ /** * Allows programmatic initialization and configuration of Logback. The * ServiceLoader is typically used to instantiate implementations and thus - * implementations will need to follow the guidelines of the ServiceLoader - * specifically a no-arg constructor is required. + * implementations will need to follow the guidelines of the ServiceLoader, + * in particular the no-arg constructor requirement. * - * The return type of {@link #configure(Context) configure} was changed from 'void' to + * The return type of {@link #configure(LoggerContext) configure} was changed from 'void' to * {@link ExecutionStatus) in logback version 1.3.0. */ public interface Configurator extends ContextAware { @@ -35,13 +36,14 @@ public interface Configurator extends ContextAware { enum ExecutionStatus { NEUTRAL, // let the caller decide INVOKE_NEXT_IF_ANY, // invoke other - DO_NOT_INVOKE_NEXT_IF_ANY + DO_NOT_INVOKE_NEXT_IF_ANY // the caller should not invoke further configurators even some are available } /** - * The context will also be set before this method is called via - * {@link ContextAware#setContext(ch.qos.logback.core.Context)}. + * Implementations of this method may expect that the {@link LoggerContext} is set with + * {@link ContextAware#setContext} before this method is invoked. + * */ - ExecutionStatus configure(Context context); + ExecutionStatus configure(LoggerContext context); } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java index 8c52bbb976..086b457002 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java @@ -112,7 +112,7 @@ private Configurator instantiateConfiguratorByClassName(String configuratorClass /** * * @param configurator - * @return true if enclosing loop should break, false otherwise + * @return ExecutionStatus */ private Configurator.ExecutionStatus invokeConfigure(Configurator configurator) { try { diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/util/DefaultJoranConfigurator.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/DefaultJoranConfigurator.java index 64eb3b14d2..9a9db50a42 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/util/DefaultJoranConfigurator.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/util/DefaultJoranConfigurator.java @@ -1,6 +1,7 @@ package ch.qos.logback.classic.util; import ch.qos.logback.classic.ClassicConstants; +import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.classic.spi.ConfiguratorRank; import ch.qos.logback.core.Context; @@ -27,7 +28,7 @@ public class DefaultJoranConfigurator extends ContextAwareBase implements Configurator { @Override - public ExecutionStatus configure(Context context) { + public ExecutionStatus configure(LoggerContext context) { URL url = performMultiStepConfigurationFileSearch(true); if (url != null) { try { diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/util/MockConfigurator.java b/logback-classic/src/test/java/ch/qos/logback/classic/util/MockConfigurator.java index 581f6e670f..718495748f 100644 --- a/logback-classic/src/test/java/ch/qos/logback/classic/util/MockConfigurator.java +++ b/logback-classic/src/test/java/ch/qos/logback/classic/util/MockConfigurator.java @@ -13,6 +13,7 @@ */ package ch.qos.logback.classic.util; +import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.spi.Configurator; import ch.qos.logback.classic.spi.ConfiguratorRank; import ch.qos.logback.core.Context; @@ -23,7 +24,7 @@ public class MockConfigurator extends ContextAwareBase implements Configurator { static Context context = null; - public ExecutionStatus configure(Context aContext) { + public ExecutionStatus configure(LoggerContext aContext) { context = aContext; return ExecutionStatus.NEUTRAL; }