Search in sources :

Example 1 with ConsoleHandler

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);
}
Also used : AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) Handler(java.util.logging.Handler) LoggingTestsHelper.getHandler(io.quarkus.logging.LoggingTestsHelper.getHandler) AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) Test(org.junit.jupiter.api.Test) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest)

Example 2 with ConsoleHandler

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");
}
Also used : PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) Formatter(java.util.logging.Formatter) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) QuarkusDelayedHandler(io.quarkus.bootstrap.logging.QuarkusDelayedHandler) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler) Handler(java.util.logging.Handler) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) Logger(java.util.logging.Logger) LogManager(java.util.logging.LogManager) QuarkusDelayedHandler(io.quarkus.bootstrap.logging.QuarkusDelayedHandler) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with ConsoleHandler

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;
}
Also used : PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler)

Example 4 with ConsoleHandler

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 });
}
Also used : PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with 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));
}
Also used : OnlyOnceErrorManager(org.jboss.logmanager.errormanager.OnlyOnceErrorManager) ErrorManager(java.util.logging.ErrorManager) ArrayList(java.util.ArrayList) LogContext(org.jboss.logmanager.LogContext) SyslogHandler(org.jboss.logmanager.handlers.SyslogHandler) FileHandler(org.jboss.logmanager.handlers.FileHandler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler) Handler(java.util.logging.Handler) AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) Logger(org.jboss.logmanager.Logger) OnlyOnceErrorManager(org.jboss.logmanager.errormanager.OnlyOnceErrorManager) Level(java.util.logging.Level) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConsoleHandler (org.jboss.logmanager.handlers.ConsoleHandler)17 Handler (java.util.logging.Handler)10 PatternFormatter (org.jboss.logmanager.formatters.PatternFormatter)7 AsyncHandler (org.jboss.logmanager.handlers.AsyncHandler)5 FileHandler (org.jboss.logmanager.handlers.FileHandler)5 SizeRotatingFileHandler (org.jboss.logmanager.handlers.SizeRotatingFileHandler)5 ColorPatternFormatter (org.jboss.logmanager.formatters.ColorPatternFormatter)4 PeriodicSizeRotatingFileHandler (org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler)4 SyslogHandler (org.jboss.logmanager.handlers.SyslogHandler)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Formatter (java.util.logging.Formatter)3 Level (java.util.logging.Level)3 Logger (java.util.logging.Logger)3 QuarkusDelayedHandler (io.quarkus.bootstrap.logging.QuarkusDelayedHandler)2 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Optional (java.util.Optional)2