use of org.jboss.logmanager.handlers.ConsoleHandler in project quarkus by quarkusio.
the class AsyncConsoleHandlerTest method asyncConsoleHandlerConfigurationTest.
@Test
public void asyncConsoleHandlerConfigurationTest() {
Handler handler = getHandler(AsyncHandler.class);
assertThat(handler.getLevel()).isEqualTo(Level.WARNING);
AsyncHandler asyncHandler = (AsyncHandler) handler;
assertThat(asyncHandler.getHandlers()).isNotEmpty();
assertThat(asyncHandler.getQueueLength()).isEqualTo(256);
assertThat(asyncHandler.getOverflowAction()).isEqualTo(AsyncHandler.OverflowAction.DISCARD);
Handler nestedConsoleHandler = Arrays.stream(asyncHandler.getHandlers()).filter(h -> (h instanceof ConsoleHandler)).findFirst().get();
ConsoleHandler consoleHandler = (ConsoleHandler) nestedConsoleHandler;
assertThat(consoleHandler.getLevel()).isEqualTo(Level.WARNING);
}
use of org.jboss.logmanager.handlers.ConsoleHandler in project quarkus by quarkusio.
the class CategoryConfiguredHandlerTest method consoleOutputTest.
@Test
public void consoleOutputTest() {
LogManager logManager = LogManager.getLogManager();
assertThat(logManager).isInstanceOf(org.jboss.logmanager.LogManager.class);
QuarkusDelayedHandler delayedHandler = InitialConfigurator.DELAYED_HANDLER;
assertThat(Logger.getLogger("").getHandlers()).contains(delayedHandler);
Handler handler = Arrays.stream(delayedHandler.getHandlers()).filter(h -> (h instanceof ConsoleHandler)).findFirst().get();
assertThat(handler).isNotNull();
assertThat(handler.getLevel()).isEqualTo(Level.WARNING);
Logger categoryLogger = logManager.getLogger("io.quarkus.category");
assertThat(categoryLogger).isNotNull();
assertThat(categoryLogger.getHandlers()).hasSize(2).extracting("class").containsExactlyInAnyOrder(ConsoleHandler.class, SizeRotatingFileHandler.class);
Logger otherCategoryLogger = logManager.getLogger("io.quarkus.othercategory");
assertThat(otherCategoryLogger).isNotNull();
assertThat(otherCategoryLogger.getHandlers()).hasSize(1).extracting("class").containsExactlyInAnyOrder(ConsoleHandler.class);
Logger anotherCategoryLogger = logManager.getLogger("io.quarkus.anothercategory");
assertThat(anotherCategoryLogger).isNotNull();
assertThat(anotherCategoryLogger.getHandlers()).isEmpty();
Formatter formatter = handler.getFormatter();
assertThat(formatter).isInstanceOf(PatternFormatter.class);
PatternFormatter patternFormatter = (PatternFormatter) formatter;
assertThat(patternFormatter.getPattern()).isEqualTo("%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n");
}
use of org.jboss.logmanager.handlers.ConsoleHandler in project quarkus by quarkusio.
the class InitialConfigurator method createDefaultHandler.
public static ConsoleHandler createDefaultHandler() {
ConsoleHandler handler = new ConsoleHandler(new PatternFormatter("%d{HH:mm:ss,SSS} %-5p [%c{3.}] %s%e%n"));
handler.setLevel(Level.INFO);
return handler;
}
use of org.jboss.logmanager.handlers.ConsoleHandler in project qbicc by qbicc.
the class SimpleAppTest method setUpHandler.
@BeforeAll
static void setUpHandler() {
org.jboss.logmanager.Logger rootLogger = org.jboss.logmanager.Logger.getLogger("");
ConsoleHandler consoleHandler = new ConsoleHandler(ConsoleHandler.Target.SYSTEM_OUT, new PatternFormatter("[%1.1p] (%c) %X{phase}: %m%n"));
rootLogger.setHandlers(new Handler[] { consoleHandler });
}
use of org.jboss.logmanager.handlers.ConsoleHandler in project quarkus by quarkusio.
the class LoggingSetupRecorder method initializeBuildTimeLogging.
public static void initializeBuildTimeLogging(LogConfig config, LogBuildTimeConfig buildConfig, ConsoleRuntimeConfig consoleConfig, LaunchMode launchMode) {
final Map<String, CategoryConfig> categories = config.categories;
final LogContext logContext = LogContext.getLogContext();
final Logger rootLogger = logContext.getLogger("");
rootLogger.setLevel(config.level);
ErrorManager errorManager = new OnlyOnceErrorManager();
final Map<String, CleanupFilterConfig> filters = config.filters;
List<LogCleanupFilterElement> filterElements = new ArrayList<>(filters.size());
for (Entry<String, CleanupFilterConfig> entry : filters.entrySet()) {
filterElements.add(new LogCleanupFilterElement(entry.getKey(), entry.getValue().targetLevel, entry.getValue().ifStartsWith));
}
LogCleanupFilter logCleanupFilter = new LogCleanupFilter(filterElements);
final ArrayList<Handler> handlers = new ArrayList<>(3);
if (config.console.enable) {
final Handler consoleHandler = configureConsoleHandler(config.console, consoleConfig, errorManager, logCleanupFilter, Collections.emptyList(), new RuntimeValue<>(Optional.empty()), launchMode);
errorManager = consoleHandler.getErrorManager();
handlers.add(consoleHandler);
}
Map<String, Handler> namedHandlers = createNamedHandlers(config, consoleConfig, Collections.emptyList(), errorManager, logCleanupFilter, launchMode);
for (Map.Entry<String, CategoryConfig> entry : categories.entrySet()) {
final String categoryName = entry.getKey();
final Level logLevel = getLogLevel(categoryName, categories, CategoryConfig::getLevel, buildConfig.minLevel);
final Level minLogLevel = getLogLevel(categoryName, buildConfig.categories, CategoryBuildTimeConfig::getMinLevel, buildConfig.minLevel);
if (logLevel.intValue() < minLogLevel.intValue()) {
log.warnf("Log level %s for category '%s' set below minimum logging level %s, promoting it to %s", logLevel, entry.getKey(), minLogLevel, minLogLevel);
entry.getValue().level = InheritableLevel.of(minLogLevel.toString());
}
}
for (Map.Entry<String, CategoryConfig> entry : categories.entrySet()) {
final String name = entry.getKey();
final Logger categoryLogger = logContext.getLogger(name);
final CategoryConfig categoryConfig = entry.getValue();
if (!categoryConfig.level.isInherited()) {
categoryLogger.setLevel(categoryConfig.level.getLevel());
}
categoryLogger.setUseParentHandlers(categoryConfig.useParentHandlers);
if (categoryConfig.handlers.isPresent()) {
addNamedHandlersToCategory(categoryConfig, namedHandlers, categoryLogger, errorManager);
}
}
InitialConfigurator.DELAYED_HANDLER.setAutoFlush(false);
InitialConfigurator.DELAYED_HANDLER.setBuildTimeHandlers(handlers.toArray(EmbeddedConfigurator.NO_HANDLERS));
}
Aggregations