Skip to content

Commit

Permalink
make static constants uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
tgracchus committed Apr 30, 2024
1 parent 1e0e7b0 commit 285b519
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/main/java/com/hivemq/bootstrap/LoggingBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public class LoggingBootstrap {

private static final Logger log = LoggerFactory.getLogger(LoggingBootstrap.class);

private static final @NotNull ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
private static final @NotNull List<Appender<ILoggingEvent>> defaultAppenders = new LinkedList<>();
private static final @NotNull LogLevelModifierTurboFilter logLevelModifierTurboFilter =
private static final @NotNull ListAppender<ILoggingEvent> LIST_APPENDER = new ListAppender<>();
private static final @NotNull List<Appender<ILoggingEvent>> DEFAULT_APPENDERS = new LinkedList<>();
private static final @NotNull LogLevelModifierTurboFilter LOG_LEVEL_MODIFIER_TURBO_FILTER =
new LogLevelModifierTurboFilter();
private static final @NotNull LogbackChangeListener logbackChangeListener = new LogbackChangeListener();
private static final @NotNull LogbackChangeListener LOGBACK_CHANGE_LISTENER = new LogbackChangeListener();

/**
* Prepares the logging. This method must be called before any logging occurs
Expand All @@ -66,12 +66,12 @@ public static void prepareLogging() {
final Appender<ILoggingEvent> next = iterator.next();
//We remove the appender for the moment
logger.detachAppender(next);
defaultAppenders.add(next);
DEFAULT_APPENDERS.add(next);
}

//This appender just adds entries to an Array List so we can queue the log statements for later
listAppender.start();
logger.addAppender(listAppender);
LIST_APPENDER.start();
logger.addAppender(LIST_APPENDER);
}

/**
Expand All @@ -81,31 +81,31 @@ public static void prepareLogging() {
public static void initLogging(final @NotNull File configFolder) {
final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

context.addListener(logbackChangeListener);
context.addListener(LOGBACK_CHANGE_LISTENER);

final boolean overridden = tryToOverrideLogbackXml(configFolder);
if (!overridden) {
reEnableDefaultAppenders();
context.addTurboFilter(logLevelModifierTurboFilter);
context.addTurboFilter(LOG_LEVEL_MODIFIER_TURBO_FILTER);
}
redirectJULToSLF4J();
logQueuedEntries();

reset();
// must be added here, as addLoglevelModifiers() is much to late
if (SystemUtils.IS_OS_WINDOWS) {
logLevelModifierTurboFilter.registerLogLevelModifier(new XodusFileDataWriterLogLevelModifier());
LOG_LEVEL_MODIFIER_TURBO_FILTER.registerLogLevelModifier(new XodusFileDataWriterLogLevelModifier());
log.trace("Added Xodus log level modifier for FileDataWriter.class");
}

logLevelModifierTurboFilter.registerLogLevelModifier(new NettyLogLevelModifier());
LOG_LEVEL_MODIFIER_TURBO_FILTER.registerLogLevelModifier(new NettyLogLevelModifier());
log.trace("Added Netty log level modifier");
}

public static void resetLogging() {
final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.getTurboFilterList().remove(logLevelModifierTurboFilter);
context.removeListener(logbackChangeListener);
context.getTurboFilterList().remove(LOG_LEVEL_MODIFIER_TURBO_FILTER);
context.removeListener(LOGBACK_CHANGE_LISTENER);
}

/**
Expand All @@ -114,7 +114,7 @@ public static void resetLogging() {
private static void reEnableDefaultAppenders() {
final ch.qos.logback.classic.Logger logger = getRootLogger();

for (final Appender<ILoggingEvent> defaultAppender : defaultAppenders) {
for (final Appender<ILoggingEvent> defaultAppender : DEFAULT_APPENDERS) {
logger.addAppender(defaultAppender);
}
}
Expand All @@ -125,10 +125,10 @@ private static void reEnableDefaultAppenders() {
private static void logQueuedEntries() {
final ch.qos.logback.classic.Logger logger = getRootLogger();

listAppender.stop();
LIST_APPENDER.stop();
//Now we need to detach the appender (if needed) so it isn't used anymore
logger.detachAppender(listAppender);
for (final ILoggingEvent loggingEvent : listAppender.list) {
logger.detachAppender(LIST_APPENDER);
for (final ILoggingEvent loggingEvent : LIST_APPENDER.list) {
logger.callAppenders(loggingEvent);
}
}
Expand Down Expand Up @@ -165,8 +165,8 @@ private static boolean tryToOverrideLogbackXml(final @NotNull File configFolder)
configurator.setContext(context);
configurator.doConfigure(file);

listAppender.start();
context.getLogger(Logger.ROOT_LOGGER_NAME).addAppender(listAppender);
LIST_APPENDER.start();
context.getLogger(Logger.ROOT_LOGGER_NAME).addAppender(LIST_APPENDER);
log.info("Log Configuration was overridden by {}", file.getAbsolutePath());
return true;
} catch (final JoranException je) {
Expand All @@ -192,16 +192,16 @@ private static boolean tryToOverrideLogbackXml(final @NotNull File configFolder)
}

public static void addLoglevelModifiers() {
logLevelModifierTurboFilter.registerLogLevelModifier(new XodusEnvironmentImplLogLevelModifier());
LOG_LEVEL_MODIFIER_TURBO_FILTER.registerLogLevelModifier(new XodusEnvironmentImplLogLevelModifier());
log.trace("Added Xodus log level modifier for EnvironmentImpl.class");
}

/**
* Resets everything to the initial state
*/
private static void reset() {
defaultAppenders.clear();
listAppender.list.clear();
DEFAULT_APPENDERS.clear();
LIST_APPENDER.list.clear();
}

private static final class LogbackChangeListener implements LoggerContextListener {
Expand All @@ -226,7 +226,7 @@ public void onStart(final @NotNull LoggerContext context) {
@Override
public void onReset(final @NotNull LoggerContext context) {
log.trace("logback.xml was changed");
context.addTurboFilter(logLevelModifierTurboFilter);
context.addTurboFilter(LOG_LEVEL_MODIFIER_TURBO_FILTER);
}

@Override
Expand Down

0 comments on commit 285b519

Please sign in to comment.