Skip to content

Commit

Permalink
set context in SerializeModelModelHandler.configure
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Jun 23, 2023
1 parent 0fb0f09 commit 79e2d54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.classic.joran.serializedModel.HardenedModelInputStream;
import ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules;
import ch.qos.logback.core.spi.Configurator;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.LogbackException;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.processor.DefaultProcessor;
import ch.qos.logback.core.model.processor.ModelInterpretationContext;
import ch.qos.logback.core.spi.Configurator;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.status.InfoStatus;
import ch.qos.logback.core.status.StatusManager;
Expand Down Expand Up @@ -52,6 +52,8 @@ public class SerializedModelConfigurator extends ContextAwareBase implements Con
@Override
public ExecutionStatus configure(Context context) {

setContext(context);

URL url = performMultiStepModelFileSearch(true);
if (url != null) {
configureByResource(url);
Expand All @@ -70,6 +72,7 @@ private void configureByResource(URL url) {
return;
}
buildModelInterpretationContext(model);

DefaultProcessor defaultProcessor = new DefaultProcessor(context, this.modelInterpretationContext);
ModelClassToModelHandlerLinker mc2mhl = new ModelClassToModelHandlerLinker(context);
mc2mhl.link(defaultProcessor);
Expand All @@ -78,7 +81,6 @@ private void configureByResource(URL url) {
synchronized (context.getConfigurationLock()) {
defaultProcessor.process(model);
}

} else {
throw new LogbackException(
"Unexpected filename extension of file [" + url.toString() + "]. Should be " + MODEL_CONFIG_FILE_EXTENSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
public class ConfigurationModel extends Model {

private static final long serialVersionUID = 1286156598561818515L;
static final String DEBUG_SYSTEM_PROPERTY_KEY = "logback.debug";
static final Duration SCAN_PERIOD_DEFAULT = Duration.buildByMinutes(1);

String debugStr;
String scanStr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public void handle(ModelInterpretationContext mic, Model model) {

// See LOGBACK-527 (the system property is looked up first). Thus, it overrides
// the equivalent property in the config file. This reversal of scope priority
// is justified
// by the use case: the admin trying to chase rogue config file
// is justified by the use case: the admin trying to chase rogue config file
String debugAttrib = OptionHelper.getSystemProperty(DEBUG_SYSTEM_PROPERTY_KEY, null);
if (debugAttrib == null) {
debugAttrib = mic.subst(configurationModel.getDebugStr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void autoConfig(ClassLoader classLoader) throws JoranException {
loggerContext.getStatusManager().add(new InfoStatus(CoreConstants.LOGBACK_CLASSIC_VERSION_MESSAGE + versionStr, loggerContext));
StatusListenerConfigHelper.installIfAsked(loggerContext);

long start = System.currentTimeMillis();
long startConfigurationAsAService = System.currentTimeMillis();
List<Configurator> configuratorList = ClassicEnvUtil.loadFromServiceLoader(Configurator.class, classLoader);

configuratorList.sort(rankComparator);
Expand All @@ -76,7 +76,7 @@ public void autoConfig(ClassLoader classLoader) throws JoranException {
c.setContext(loggerContext);
Configurator.ExecutionStatus status = c.configure(loggerContext);
if (status == Configurator.ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY) {
printConfigurationAsAServiveDuration(start, true);
printDuration(startConfigurationAsAService, "Configuration as a service duration ", true);
return;
}
} catch (Exception e) {
Expand All @@ -85,21 +85,25 @@ public void autoConfig(ClassLoader classLoader) throws JoranException {
}
}

printConfigurationAsAServiveDuration(start, false);
printDuration(startConfigurationAsAService, "Configuration as a service duration ", false);

long startJoranConfiguration = System.currentTimeMillis();
Configurator.ExecutionStatus es = attemptConfigurationUsingJoranUsingReflexion(classLoader);

if (es == Configurator.ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY)
if (es == Configurator.ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY) {
printDuration(startJoranConfiguration, "JoranConfiguration duration", true);
return;
}
printDuration(startJoranConfiguration, "JoranConfiguration duration", false);

// at this stage invoke basicConfigurator
fallbackOnToBasicConfigurator();
}

private void printConfigurationAsAServiveDuration(long start, boolean success) {
private void printDuration(long start, String message, boolean success) {
long end = System.currentTimeMillis();
long configurationAsAServiceDuration = end - start;
contextAware.addInfo("Configuration as a service lasted "+configurationAsAServiceDuration + " milliseconds. Success status="+success);
contextAware.addInfo(message+configurationAsAServiceDuration + " milliseconds. Success status="+success);
}

private Configurator.ExecutionStatus attemptConfigurationUsingJoranUsingReflexion(ClassLoader classLoader) {
Expand Down

0 comments on commit 79e2d54

Please sign in to comment.