Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip redundant LoggerContext reset #41910

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
* @author Dave Syer
* @author Andy Wilkinson
* @author Ben Hale
* @author Mark Chesney
* @since 1.0.0
*/
public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanFactoryInitializationAotProcessor {
Expand Down Expand Up @@ -210,7 +211,7 @@ private boolean initializeFromAotGeneratedArtifactsIfPossible(LoggingInitializat
applySystemProperties(initializationContext.getEnvironment(), logFile);
}
LoggerContext loggerContext = getLoggerContext();
stopAndReset(loggerContext);
stopOrReset(loggerContext);
SpringBootJoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
configurator.setContext(loggerContext);
boolean configuredUsingAotGeneratedArtifacts = configurator.configureUsingAotGeneratedArtifacts();
Expand All @@ -223,7 +224,7 @@ private boolean initializeFromAotGeneratedArtifactsIfPossible(LoggingInitializat
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) {
LoggerContext context = getLoggerContext();
stopAndReset(context);
stopOrReset(context);
withLoggingSuppressed(() -> {
boolean debug = Boolean.getBoolean("logback.debug");
if (debug) {
Expand All @@ -245,7 +246,7 @@ protected void loadDefaults(LoggingInitializationContext initializationContext,
protected void loadConfiguration(LoggingInitializationContext initializationContext, String location,
LogFile logFile) {
LoggerContext loggerContext = getLoggerContext();
stopAndReset(loggerContext);
stopOrReset(loggerContext);
withLoggingSuppressed(() -> {
if (initializationContext != null) {
applySystemProperties(initializationContext.getEnvironment(), logFile);
Expand Down Expand Up @@ -298,9 +299,13 @@ private void configureByResourceUrl(LoggingInitializationContext initializationC
}
}

private void stopAndReset(LoggerContext loggerContext) {
loggerContext.stop();
loggerContext.reset();
private void stopOrReset(LoggerContext loggerContext) {
if (loggerContext.isStarted()) {
loggerContext.stop();
}
else {
loggerContext.reset();
}
if (isBridgeHandlerInstalled()) {
addLevelChangePropagator(loggerContext);
}
Expand Down