From 32a4909c70eb08f3da65c23f119c4057c20485bb Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 23 Sep 2021 14:55:51 +0300 Subject: [PATCH] Enable logging from integration tests Fixes: #20303 --- .../io/quarkus/runtime/logging/ConsoleConfig.java | 3 ++- .../io/quarkus/test/junit/IntegrationTestUtil.java | 14 ++++++++++++++ .../junit/QuarkusIntegrationTestExtension.java | 4 +++- .../junit/QuarkusMainIntegrationTestExtension.java | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/ConsoleConfig.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/ConsoleConfig.java index e888f45159bc7c..a3ceae52db4928 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/logging/ConsoleConfig.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/ConsoleConfig.java @@ -9,6 +9,7 @@ @ConfigGroup public class ConsoleConfig { + public static final String DEFAULT_CONSOLE_CONFIG_FORMAT = "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n"; /** * If console logging should be enabled */ @@ -25,7 +26,7 @@ public class ConsoleConfig { * The log format. Note that this value will be ignored if an extension is present that takes * control of console formatting (e.g. an XML or JSON-format extension). */ - @ConfigItem(defaultValue = "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n") + @ConfigItem(defaultValue = DEFAULT_CONSOLE_CONFIG_FORMAT) String format; /** diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java index 33c9cb3d4a18d4..f4f3318d8c6795 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java @@ -26,12 +26,18 @@ import java.util.Properties; import java.util.Set; import java.util.function.BiConsumer; +import java.util.logging.Handler; +import java.util.logging.Level; import java.util.stream.Collectors; import javax.enterprise.inject.Alternative; import javax.inject.Inject; +import io.quarkus.runtime.logging.LoggingSetupRecorder; import org.jboss.jandex.Index; +import org.jboss.logmanager.formatters.ColorPatternFormatter; +import org.jboss.logmanager.formatters.PatternFormatter; +import org.jboss.logmanager.handlers.ConsoleHandler; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.platform.commons.JUnitException; @@ -39,12 +45,16 @@ import io.quarkus.bootstrap.app.AugmentAction; import io.quarkus.bootstrap.app.CuratedApplication; import io.quarkus.bootstrap.app.QuarkusBootstrap; +import io.quarkus.bootstrap.logging.InitialConfigurator; +import io.quarkus.bootstrap.logging.QuarkusDelayedHandler; import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.model.gradle.QuarkusModel; import io.quarkus.bootstrap.util.PathsUtils; import io.quarkus.bootstrap.utils.BuildToolHelper; import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem; +import io.quarkus.dev.console.QuarkusConsole; import io.quarkus.runtime.configuration.ProfileManager; +import io.quarkus.runtime.logging.ConsoleConfig; import io.quarkus.test.common.ArtifactLauncher; import io.quarkus.test.common.PathTestHelper; import io.quarkus.test.common.TestClassIndexer; @@ -295,6 +305,10 @@ public void accept(String s, String s2) { return new DefaultDevServicesLaunchResult(propertyMap, networkId, curatedApplication); } + + static void activateLogging() { + LoggingSetupRecorder.handleFailedStart(); + } static class DefaultDevServicesLaunchResult implements ArtifactLauncher.InitContext.DevServicesLaunchResult { private final Map properties; diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java index 4aee12aea1add8..0395143536cfaf 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java @@ -1,5 +1,6 @@ package io.quarkus.test.junit; +import static io.quarkus.test.junit.IntegrationTestUtil.*; import static io.quarkus.test.junit.IntegrationTestUtil.determineBuildOutputDirectory; import static io.quarkus.test.junit.IntegrationTestUtil.determineTestProfileAndProperties; import static io.quarkus.test.junit.IntegrationTestUtil.doProcessTestInstance; @@ -84,7 +85,7 @@ private IntegrationTestExtensionState ensureStarted(ExtensionContext extensionCo ExtensionContext.Store store = root.getStore(ExtensionContext.Namespace.GLOBAL); IntegrationTestExtensionState state = store.get(IntegrationTestExtensionState.class.getName(), IntegrationTestExtensionState.class); - Class selectedProfile = IntegrationTestUtil.findProfile(testClass); + Class selectedProfile = findProfile(testClass); boolean wrongProfile = !Objects.equals(selectedProfile, quarkusTestProfile); // we reload the test resources if we changed test class and if we had or will have per-test test resources boolean reloadTestResources = !Objects.equals(extensionContext.getRequiredTestClass(), currentJUnitTestClass) @@ -184,6 +185,7 @@ public void close() throws Throwable { "Artifact type + '" + artifactType + "' is not supported by @QuarkusIntegrationTest"); } + activateLogging(); startLauncher(launcher, additionalProperties, () -> ssl = true); IntegrationTestExtensionState state = new IntegrationTestExtensionState(testResourceManager, launcher, diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java index 05520715721a7c..e50da9059ac40d 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java @@ -1,5 +1,6 @@ package io.quarkus.test.junit; +import static io.quarkus.test.junit.IntegrationTestUtil.activateLogging; import static io.quarkus.test.junit.IntegrationTestUtil.determineBuildOutputDirectory; import static io.quarkus.test.junit.IntegrationTestUtil.determineTestProfileAndProperties; import static io.quarkus.test.junit.IntegrationTestUtil.getAdditionalTestResources; @@ -148,6 +149,7 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S } launcher.includeAsSysProps(additionalProperties); + activateLogging(); return launcher.runToCompletion(args); } finally {