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

Improve ShamrockUnitTest logging #371

Merged
merged 1 commit into from
Dec 21, 2018
Merged
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
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