Skip to content

Commit

Permalink
Logging > Register our TurboFilter only once. During the HiveMQ start…
Browse files Browse the repository at this point in the history
… we load our logback.xml which will reset the current context and call the reset which will register the TurboFilter a second time.
  • Loading branch information
A-Imal committed Nov 9, 2023
1 parent e56af0f commit 5128a3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/hivemq/HiveMQServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public void stop() {
if (configService.persistenceConfigurationService().getMode() == PersistenceMode.FILE) {
dataLock.unlock();
}
LoggingBootstrap.resetLogging();
}

public @Nullable Injector getInjector() {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/hivemq/bootstrap/LoggingBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class LoggingBootstrap {
private static final List<Appender<ILoggingEvent>> 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
Expand Down Expand Up @@ -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());
Expand All @@ -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
*/
Expand Down

0 comments on commit 5128a3e

Please sign in to comment.