diff --git a/src/main/java/com/hivemq/HiveMQServer.java b/src/main/java/com/hivemq/HiveMQServer.java index 7810606d5..5f8873821 100644 --- a/src/main/java/com/hivemq/HiveMQServer.java +++ b/src/main/java/com/hivemq/HiveMQServer.java @@ -262,6 +262,7 @@ public void stop() { if (configService.persistenceConfigurationService().getMode() == PersistenceMode.FILE) { dataLock.unlock(); } + LoggingBootstrap.resetLogging(); } public @Nullable Injector getInjector() { diff --git a/src/main/java/com/hivemq/bootstrap/LoggingBootstrap.java b/src/main/java/com/hivemq/bootstrap/LoggingBootstrap.java index bb9a706d6..e67adffff 100644 --- a/src/main/java/com/hivemq/bootstrap/LoggingBootstrap.java +++ b/src/main/java/com/hivemq/bootstrap/LoggingBootstrap.java @@ -52,6 +52,7 @@ public class LoggingBootstrap { private static final List> defaultAppenders = new LinkedList<>(); private static final @NotNull LogLevelModifierTurboFilter logLevelModifierTurboFilter = new LogLevelModifierTurboFilter(); + private static final @NotNull LogbackChangeListener logbackChangeListener = new LogbackChangeListener(); /** * Prepares the logging. This method must be called before any logging occurs @@ -85,20 +86,19 @@ public static void initLogging(final @NotNull File configFolder) { final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); - context.addListener(new LogbackChangeListener()); + context.addListener(logbackChangeListener); final boolean overridden = overrideLogbackXml(configFolder); if (!overridden) { reEnableDefaultAppenders(); + context.addTurboFilter(logLevelModifierTurboFilter); } redirectJULToSLF4J(); logQueuedEntries(); reset(); - context.addTurboFilter(logLevelModifierTurboFilter); - // must be added here, as addLoglevelModifiers() is much to late if (SystemUtils.IS_OS_WINDOWS) { logLevelModifierTurboFilter.registerLogLevelModifier(new XodusFileDataWriterLogLevelModifier()); @@ -109,6 +109,12 @@ public static void initLogging(final @NotNull File configFolder) { log.trace("Added Netty log level modifier"); } + public static void resetLogging() { + final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); + context.getTurboFilterList().remove(logLevelModifierTurboFilter); + context.removeListener(logbackChangeListener); + } + /** * Re-enables all default appenders that were removed from the root logger for startup */