Skip to content

Commit

Permalink
Merge pull request #371 from stuartwdouglas/test-logging
Browse files Browse the repository at this point in the history
Improve ShamrockUnitTest logging
  • Loading branch information
stuartwdouglas authored Dec 21, 2018
2 parents acd4e86 + b0558c5 commit 75e44af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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;
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.
#

org.jboss.shamrock.dev.DevModeLogging
org.jboss.shamrock.runner.RuntimeLoggingConfigurator
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 75e44af

Please sign in to comment.