Restore LoggingSystems’ previous cleanup behaviour
This commit reverts the changes made for gh-4026. Those changes updated each LoggingSystem to close/stop the underlying logging system as part of the clean up processing. Unfortunately, this approach doesn’t work in an environment where their are multiple application contexts and some have a shorter lifecycle than the “main” application context. In such an environment, closing an application context with a shorter lifecycle prior to the main application context being closed will close/stop the main application context’s logging system as, rather than being scoped to an application context, a logging system is shared across multiple application contexts. (The exact details of how widely shared the logging system is varies between logging systems and, in the case of Logback and Log4J2, also depends on which ContextSelector implementation is being used.
This commit is contained in:
parent
e98aac4327
commit
a76e84addc
|
@ -113,10 +113,4 @@ public class JavaLoggingSystem extends AbstractLoggingSystem {
|
|||
logger.setLevel(LEVELS.get(level));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
super.cleanUp();
|
||||
LogManager.getLogManager().reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -115,10 +115,4 @@ public class Log4JLoggingSystem extends Slf4JLoggingSystem {
|
|||
logger.setLevel(LEVELS.get(level));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
super.cleanUp();
|
||||
LogManager.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -152,12 +152,6 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
|
|||
loadConfiguration(location, logFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
super.cleanUp();
|
||||
getLoggerContext().stop();
|
||||
}
|
||||
|
||||
protected void loadConfiguration(String location, LogFile logFile) {
|
||||
Assert.notNull(location, "Location must not be null");
|
||||
if (logFile != null) {
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.springframework.util.Assert;
|
|||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import ch.qos.logback.classic.BasicConfigurator;
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.joran.JoranConfigurator;
|
||||
|
@ -178,8 +177,6 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|||
public void cleanUp() {
|
||||
super.cleanUp();
|
||||
getLoggerContext().getStatusManager().clear();
|
||||
getLoggerContext().stop();
|
||||
BasicConfigurator.configure(getLoggerContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,9 +20,6 @@ import java.io.File;
|
|||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import org.apache.commons.logging.impl.Jdk14Logger;
|
||||
import org.junit.After;
|
||||
|
@ -37,7 +34,6 @@ import org.springframework.util.StringUtils;
|
|||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -164,33 +160,4 @@ public class JavaLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanUpResetsLogManager() throws Exception {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.loggingSystem.initialize(null, null, null);
|
||||
this.logger.getLogger().addHandler(new NoOpHandler());
|
||||
assertThat(this.logger.getLogger().getHandlers().length, is(equalTo(1)));
|
||||
LogManager.getLogManager().reset();
|
||||
assertThat(this.logger.getLogger().getHandlers().length, is(equalTo(0)));
|
||||
}
|
||||
|
||||
private static final class NoOpHandler extends Handler {
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -139,17 +139,6 @@ public class Log4JLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
assertFalse(bridgeHandlerInstalled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanUpStopsLogManager() {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.loggingSystem.initialize(null, null, null);
|
||||
assertTrue(org.apache.log4j.LogManager.getLoggerRepository().getRootLogger()
|
||||
.getAllAppenders().hasMoreElements());
|
||||
this.loggingSystem.cleanUp();
|
||||
assertFalse(org.apache.log4j.LogManager.getLoggerRepository().getRootLogger()
|
||||
.getAllAppenders().hasMoreElements());
|
||||
}
|
||||
|
||||
private boolean bridgeHandlerInstalled() {
|
||||
java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("");
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.List;
|
|||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.LoggerContext;
|
||||
import org.apache.logging.log4j.core.config.Configuration;
|
||||
import org.apache.logging.log4j.core.config.FileConfigurationMonitor;
|
||||
import org.hamcrest.Matcher;
|
||||
|
@ -239,17 +238,6 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanupStopsContext() throws Exception {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.logger.info("Hidden");
|
||||
this.loggingSystem.initialize(null, null, null);
|
||||
LoggerContext context = (LoggerContext) LogManager.getContext(false);
|
||||
assertFalse(context.isStopped());
|
||||
this.loggingSystem.cleanUp();
|
||||
assertTrue(context.isStopped());
|
||||
}
|
||||
|
||||
private static class TestLog4J2LoggingSystem extends Log4J2LoggingSystem {
|
||||
|
||||
private List<String> availableClasses = new ArrayList<String>();
|
||||
|
@ -259,7 +247,8 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return ((LoggerContext) LogManager.getContext(false)).getConfiguration();
|
||||
return ((org.apache.logging.log4j.core.LoggerContext) LogManager
|
||||
.getContext(false)).getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,7 +51,6 @@ import static org.hamcrest.Matchers.not;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -122,7 +121,6 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
@Test
|
||||
public void testBasicConfigLocation() throws Exception {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.loggingSystem.initialize(this.initializationContext, null, null);
|
||||
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
|
||||
LoggerContext context = (LoggerContext) factory;
|
||||
Logger root = context.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
|
||||
|
@ -307,19 +305,6 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanUpStopsContext() throws Exception {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.loggingSystem.initialize(this.initializationContext, null, null);
|
||||
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
|
||||
LoggerContext context = (LoggerContext) factory;
|
||||
Logger root = context.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
|
||||
assertNotNull(root.getAppender("CONSOLE"));
|
||||
|
||||
this.loggingSystem.cleanUp();
|
||||
assertNull(root.getAppender("CONSOLE"));
|
||||
}
|
||||
|
||||
private String getLineWithText(File file, String outputSearch) throws Exception {
|
||||
return getLineWithText(FileCopyUtils.copyToString(new FileReader(file)),
|
||||
outputSearch);
|
||||
|
|
Loading…
Reference in New Issue