Avoid installing unwanted ConsoleHandler when cleaning up

Closes gh-13470
pull/14003/head
Andy Wilkinson 6 years ago
parent 01abb196ef
commit 06b4007ce4

@ -50,7 +50,6 @@ public abstract class Slf4JLoggingSystem extends AbstractLoggingSystem {
public void cleanUp() {
if (isBridgeHandlerAvailable()) {
removeJdkLoggingBridgeHandler();
reinstateConsoleHandlerIfNecessary();
}
}
@ -81,17 +80,18 @@ public abstract class Slf4JLoggingSystem extends AbstractLoggingSystem {
* @since 2.0.4
*/
protected final boolean isBridgeJulIntoSlf4j() {
return isBridgeHandlerAvailable() && isJulUsingItsDefaultConfiguration();
return isBridgeHandlerAvailable() && isJulUsingASingleConsoleHandlerAtMost();
}
protected final boolean isBridgeHandlerAvailable() {
return ClassUtils.isPresent(BRIDGE_HANDLER, getClassLoader());
}
private boolean isJulUsingItsDefaultConfiguration() {
private boolean isJulUsingASingleConsoleHandlerAtMost() {
Logger rootLogger = LogManager.getLogManager().getLogger("");
Handler[] handlers = rootLogger.getHandlers();
return handlers.length == 1 && handlers[0] instanceof ConsoleHandler;
return handlers.length == 0
|| (handlers.length == 1 && handlers[0] instanceof ConsoleHandler);
}
private void removeJdkLoggingBridgeHandler() {
@ -117,11 +117,4 @@ public abstract class Slf4JLoggingSystem extends AbstractLoggingSystem {
}
}
private void reinstateConsoleHandlerIfNecessary() {
Logger rootLogger = LogManager.getLogManager().getLogger("");
if (rootLogger.getHandlers().length == 0) {
rootLogger.addHandler(new ConsoleHandler());
}
}
}

Loading…
Cancel
Save