Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/logging-issue-regarding-osgi #476

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions src/main/java/com/hivemq/HiveMQServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,28 @@ public class HiveMQServer {
private final @NotNull SystemInformation systemInformation;
private final @NotNull MetricRegistry metricRegistry;
private final boolean migrate;
private final boolean loggingBootstrapEnabled;

private @Nullable Injector injector;
private @Nullable FullConfigurationService configService;

public HiveMQServer() {
this(new SystemInformationImpl(true), new MetricRegistry(), null, true);
this(new SystemInformationImpl(true), new MetricRegistry(), null, true, true);
}

public HiveMQServer(
final @NotNull SystemInformation systemInformation,
final @Nullable MetricRegistry metricRegistry,
final @Nullable FullConfigurationService configService,
final boolean loggingBootstrapEnabled,
final boolean migrate) {
hivemqId = new HivemqId();
lifecycleModule = new LifecycleModule();
dataLock = new DataLock();
this.systemInformation = systemInformation;
this.metricRegistry = metricRegistry;
this.configService = configService;
this.loggingBootstrapEnabled = loggingBootstrapEnabled;
this.migrate = migrate;
}

Expand All @@ -105,7 +108,9 @@ public void bootstrap() throws Exception {

metricRegistry.addListener(new MetricRegistryLogger());

LoggingBootstrap.prepareLogging();
if (loggingBootstrapEnabled) {
LoggingBootstrap.prepareLogging();
}

log.info("Starting HiveMQ Community Edition Server");

Expand All @@ -117,7 +122,10 @@ public void bootstrap() throws Exception {
}

log.trace("Initializing Logging");
LoggingBootstrap.initLogging(systemInformation.getConfigFolder());

if (loggingBootstrapEnabled) {
LoggingBootstrap.initLogging(systemInformation.getConfigFolder());
}

log.trace("Initializing Exception handlers");
HiveMQExceptionHandlerBootstrap.addUnrecoverableExceptionHandler();
Expand Down Expand Up @@ -216,7 +224,10 @@ public void startInstance(final @Nullable EmbeddedExtension embeddedExtension) t

/* It's important that we are modifying the log levels after Guice is initialized,
otherwise this somehow interferes with Singleton creation */
LoggingBootstrap.addLoglevelModifiers();
if (loggingBootstrapEnabled) {
LoggingBootstrap.addLoglevelModifiers();
}

instance.start(embeddedExtension);
}

Expand Down Expand Up @@ -262,7 +273,9 @@ public void stop() {
if (configService.persistenceConfigurationService().getMode() == PersistenceMode.FILE) {
dataLock.unlock();
}
LoggingBootstrap.resetLogging();
if (loggingBootstrapEnabled) {
LoggingBootstrap.resetLogging();
}
}

public @Nullable Injector getInjector() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/hivemq/configuration/SystemProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class SystemProperties {
public static final String EXTENSIONS_FOLDER = "hivemq.extensions.folder";

public static final String DIAGNOSTIC_MODE = "diagnosticMode";

public static final String EMBEDDED_LOG_BOOTSTRAP_DISABLED = "hivemq.embedded.log.bootstrap.disabled";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.inject.Injector;
import com.hivemq.HiveMQServer;
import com.hivemq.configuration.ConfigurationBootstrap;
import com.hivemq.configuration.SystemProperties;
import com.hivemq.configuration.info.SystemInformationImpl;
import com.hivemq.configuration.service.FullConfigurationService;
import com.hivemq.configuration.service.InternalConfigurations;
Expand Down Expand Up @@ -50,6 +51,9 @@ class EmbeddedHiveMQImpl implements EmbeddedHiveMQ {

private final @NotNull SystemInformationImpl systemInformation;
private final @NotNull MetricRegistry metricRegistry;
private final @NotNull boolean loggingBootstrapEnabled =
!Boolean.parseBoolean(System.getProperty(SystemProperties.EMBEDDED_LOG_BOOTSTRAP_DISABLED, "false"));

@VisibleForTesting
final @NotNull ExecutorService stateChangeExecutor;
private final @Nullable EmbeddedExtension embeddedExtension;
Expand Down Expand Up @@ -146,7 +150,7 @@ private void stateChange() {
systemInformation.init();
configurationService = ConfigurationBootstrap.bootstrapConfig(systemInformation);

hiveMQServer = new HiveMQServer(systemInformation, metricRegistry, configurationService, false);
hiveMQServer = new HiveMQServer(systemInformation, metricRegistry, configurationService, loggingBootstrapEnabled, false);
hiveMQServer.bootstrap();
hiveMQServer.startInstance(embeddedExtension);

Expand Down