diff --git a/src/main/java/com/hivemq/HiveMQServer.java b/src/main/java/com/hivemq/HiveMQServer.java index 5f8873821..10f50d90e 100644 --- a/src/main/java/com/hivemq/HiveMQServer.java +++ b/src/main/java/com/hivemq/HiveMQServer.java @@ -66,18 +66,20 @@ public class HiveMQServer { private final @NotNull SystemInformation systemInformation; private final @NotNull MetricRegistry metricRegistry; private final boolean migrate; + private final boolean enableLoggingBootstrap; 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 enableLoggingBootstrap, final boolean migrate) { hivemqId = new HivemqId(); lifecycleModule = new LifecycleModule(); @@ -85,6 +87,7 @@ public HiveMQServer( this.systemInformation = systemInformation; this.metricRegistry = metricRegistry; this.configService = configService; + this.enableLoggingBootstrap = enableLoggingBootstrap; this.migrate = migrate; } @@ -105,7 +108,9 @@ public void bootstrap() throws Exception { metricRegistry.addListener(new MetricRegistryLogger()); - LoggingBootstrap.prepareLogging(); + if (enableLoggingBootstrap) { + LoggingBootstrap.prepareLogging(); + } log.info("Starting HiveMQ Community Edition Server"); @@ -116,8 +121,11 @@ public void bootstrap() throws Exception { systemInformation.init(); } - log.trace("Initializing Logging"); - LoggingBootstrap.initLogging(systemInformation.getConfigFolder()); + if (enableLoggingBootstrap) { + log.trace("Initializing Logging"); + + LoggingBootstrap.initLogging(systemInformation.getConfigFolder()); + } log.trace("Initializing Exception handlers"); HiveMQExceptionHandlerBootstrap.addUnrecoverableExceptionHandler(); @@ -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 (enableLoggingBootstrap) { + LoggingBootstrap.addLoglevelModifiers(); + } + instance.start(embeddedExtension); } @@ -262,7 +273,9 @@ public void stop() { if (configService.persistenceConfigurationService().getMode() == PersistenceMode.FILE) { dataLock.unlock(); } - LoggingBootstrap.resetLogging(); + if (enableLoggingBootstrap) { + LoggingBootstrap.resetLogging(); + } } public @Nullable Injector getInjector() { diff --git a/src/main/java/com/hivemq/embedded/EmbeddedHiveMQBuilder.java b/src/main/java/com/hivemq/embedded/EmbeddedHiveMQBuilder.java index 5cac4cf41..8f3f8b010 100644 --- a/src/main/java/com/hivemq/embedded/EmbeddedHiveMQBuilder.java +++ b/src/main/java/com/hivemq/embedded/EmbeddedHiveMQBuilder.java @@ -74,6 +74,14 @@ public interface EmbeddedHiveMQBuilder { */ @NotNull EmbeddedHiveMQBuilder withEmbeddedExtension(@Nullable EmbeddedExtension embeddedExtension); + /** + * Disables the internal logging bootstrap, for the case any logging is already provided by other frameworks, + * such as OSGi or Springboot. + * + * @return this builder. + */ + @NotNull EmbeddedHiveMQBuilder withoutLoggingBootstrap(); + /** * Concludes the EmbeddedHiveMQ build process. *
diff --git a/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQBuilderImpl.java b/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQBuilderImpl.java
index b9a690d76..f9e0a270a 100644
--- a/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQBuilderImpl.java
+++ b/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQBuilderImpl.java
@@ -35,6 +35,7 @@ public class EmbeddedHiveMQBuilderImpl implements EmbeddedHiveMQBuilder {
private @Nullable Path dataFolder = null;
private @Nullable Path extensionsFolder = null;
private @Nullable EmbeddedExtension embeddedExtension = null;
+ private boolean enableLoggingBootstrap = true;
@Override
public @NotNull EmbeddedHiveMQBuilder withConfigurationFolder(final @Nullable Path configFolder) {
@@ -60,6 +61,12 @@ public class EmbeddedHiveMQBuilderImpl implements EmbeddedHiveMQBuilder {
return this;
}
+ @Override
+ public @NotNull EmbeddedHiveMQBuilder withoutLoggingBootstrap() {
+ this.enableLoggingBootstrap = false;
+ return this;
+ }
+
@Override
public @NotNull EmbeddedHiveMQ build() {
// Shim for the old API
@@ -67,7 +74,7 @@ public class EmbeddedHiveMQBuilderImpl implements EmbeddedHiveMQBuilder {
final File dataFile = dataFolder == null ? null : dataFolder.toFile();
final File extensionsFile = extensionsFolder == null ? null : extensionsFolder.toFile();
- return new EmbeddedHiveMQImpl(confFile, dataFile, extensionsFile, embeddedExtension);
+ return new EmbeddedHiveMQImpl(confFile, dataFile, extensionsFile, embeddedExtension, enableLoggingBootstrap);
}
}
diff --git a/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQImpl.java b/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQImpl.java
index de55b89ea..b3b508fe2 100644
--- a/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQImpl.java
+++ b/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQImpl.java
@@ -64,17 +64,21 @@ class EmbeddedHiveMQImpl implements EmbeddedHiveMQ {
private @NotNull LinkedList