From b0558c5169dad052e3f371823e563154da551496 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Fri, 21 Dec 2018 13:10:24 +1100 Subject: [PATCH] Improve ShamrockUnitTest logging --- .../runner/RuntimeLoggingConfigurator.java | 31 +++++++++++++++---- .../org.jboss.logmanager.EmbeddedConfigurator | 2 +- .../jboss/shamrock/test/ShamrockUnitTest.java | 4 +++ 3 files changed, 30 insertions(+), 7 deletions(-) rename devmode/src/main/java/org/jboss/shamrock/dev/DevModeLogging.java => core/deployment/src/main/java/org/jboss/shamrock/runner/RuntimeLoggingConfigurator.java (68%) rename {devmode => core/deployment}/src/main/resources/META-INF/services/org.jboss.logmanager.EmbeddedConfigurator (91%) diff --git a/devmode/src/main/java/org/jboss/shamrock/dev/DevModeLogging.java b/core/deployment/src/main/java/org/jboss/shamrock/runner/RuntimeLoggingConfigurator.java similarity index 68% rename from devmode/src/main/java/org/jboss/shamrock/dev/DevModeLogging.java rename to core/deployment/src/main/java/org/jboss/shamrock/runner/RuntimeLoggingConfigurator.java index 890a8037d4c53..8ab25389d044c 100644 --- a/devmode/src/main/java/org/jboss/shamrock/dev/DevModeLogging.java +++ b/core/deployment/src/main/java/org/jboss/shamrock/runner/RuntimeLoggingConfigurator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jboss.shamrock.dev; +package org.jboss.shamrock.runner; import java.util.Optional; import java.util.logging.Handler; @@ -27,7 +27,11 @@ import org.jboss.logmanager.formatters.PatternFormatter; import org.jboss.logmanager.handlers.ConsoleHandler; -public class DevModeLogging implements EmbeddedConfigurator { +/** + * Embedded configurator that can be used to configure logging in a similar + * manner to the auto generated configurator. + */ +public class RuntimeLoggingConfigurator implements EmbeddedConfigurator { static final Config config = ConfigProvider.getConfig(); @@ -43,7 +47,22 @@ public Level getLevelOf(final String loggerName) { } level = config.getOptionalValue("shamrock.log.level", String.class); if (level.isPresent()) { - return Level.parse(level.get()); + switch (level.get()) { + case "FATAL": + return org.jboss.logmanager.Level.FATAL; + case "ERROR": + return org.jboss.logmanager.Level.ERROR; + case "WARN": + return org.jboss.logmanager.Level.WARN; + case "INFO": + return org.jboss.logmanager.Level.INFO; + case "DEBUG": + return org.jboss.logmanager.Level.DEBUG; + case "TRACE": + return org.jboss.logmanager.Level.TRACE; + default: + return org.jboss.logmanager.Level.parse((level.get())); + } } return Level.INFO; } @@ -56,18 +75,18 @@ public Handler[] getHandlersOf(final String loggerName) { .orElse(true); if (color) { - return loggerName.isEmpty() ? new Handler[] { + return loggerName.isEmpty() ? new Handler[]{ new ConsoleHandler(new ColorPatternFormatter(format)) } : NO_HANDLERS; } else { - return loggerName.isEmpty() ? new Handler[] { + return loggerName.isEmpty() ? new Handler[]{ new ConsoleHandler(new PatternFormatter(format)) } : NO_HANDLERS; } } static Config getConfig() { - if(Thread.currentThread().getContextClassLoader() == null) { + if (Thread.currentThread().getContextClassLoader() == null) { return config; } else { return ConfigProvider.getConfig(); diff --git a/devmode/src/main/resources/META-INF/services/org.jboss.logmanager.EmbeddedConfigurator b/core/deployment/src/main/resources/META-INF/services/org.jboss.logmanager.EmbeddedConfigurator similarity index 91% rename from devmode/src/main/resources/META-INF/services/org.jboss.logmanager.EmbeddedConfigurator rename to core/deployment/src/main/resources/META-INF/services/org.jboss.logmanager.EmbeddedConfigurator index 51bd4b5bbe2f1..3512c5abe6320 100644 --- a/devmode/src/main/resources/META-INF/services/org.jboss.logmanager.EmbeddedConfigurator +++ b/core/deployment/src/main/resources/META-INF/services/org.jboss.logmanager.EmbeddedConfigurator @@ -14,4 +14,4 @@ # limitations under the License. # -org.jboss.shamrock.dev.DevModeLogging \ No newline at end of file +org.jboss.shamrock.runner.RuntimeLoggingConfigurator \ No newline at end of file diff --git a/test-framework/junit/src/main/java/org/jboss/shamrock/test/ShamrockUnitTest.java b/test-framework/junit/src/main/java/org/jboss/shamrock/test/ShamrockUnitTest.java index c7636da854705..0dc8d8b0f9c94 100644 --- a/test-framework/junit/src/main/java/org/jboss/shamrock/test/ShamrockUnitTest.java +++ b/test-framework/junit/src/main/java/org/jboss/shamrock/test/ShamrockUnitTest.java @@ -47,6 +47,10 @@ public class ShamrockUnitTest extends BlockJUnit4ClassRunner { + static { + System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager"); + } + private static Path deploymentDir; private static RuntimeRunner runtimeRunner;