Search in sources :

Example 1 with AsyncHandler

use of org.jboss.logmanager.handlers.AsyncHandler 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 AsyncHandler

use of org.jboss.logmanager.handlers.AsyncHandler in project quarkus by quarkusio.

the class AsyncSyslogHandlerTest method asyncSyslogHandlerConfigurationTest.

@Test
public void asyncSyslogHandlerConfigurationTest() throws NullPointerException {
    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 nestedSyslogHandler = Arrays.stream(asyncHandler.getHandlers()).filter(h -> (h instanceof SyslogHandler)).findFirst().get();
    SyslogHandler syslogHandler = (SyslogHandler) nestedSyslogHandler;
    assertThat(syslogHandler.getPort()).isEqualTo(5144);
    assertThat(syslogHandler.getAppName()).isEqualTo("quarkus");
    assertThat(syslogHandler.getHostname()).isEqualTo("quarkus-test");
    assertThat(syslogHandler.getFacility()).isEqualTo(SyslogHandler.Facility.LOG_ALERT);
    assertThat(syslogHandler.getSyslogType()).isEqualTo(SyslogHandler.SyslogType.RFC3164);
    assertThat(syslogHandler.getProtocol()).isEqualTo(SyslogHandler.Protocol.UDP);
    assertThat(syslogHandler.isUseCountingFraming()).isEqualTo(true);
    assertThat(syslogHandler.isTruncate()).isEqualTo(false);
    assertThat(syslogHandler.isBlockOnReconnect()).isEqualTo(false);
}
Also used : SyslogHandler(org.jboss.logmanager.handlers.SyslogHandler) AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) SyslogHandler(org.jboss.logmanager.handlers.SyslogHandler) Handler(java.util.logging.Handler) LoggingTestsHelper.getHandler(io.quarkus.logging.LoggingTestsHelper.getHandler) AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) Test(org.junit.jupiter.api.Test) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest)

Example 3 with AsyncHandler

use of org.jboss.logmanager.handlers.AsyncHandler in project quarkus by quarkusio.

the class ApplicationLifecycleManager method ensureConsoleLogsDrained.

// this is needed only when async console logging is enabled
private static void ensureConsoleLogsDrained() {
    AsyncHandler asyncHandler = null;
    for (Handler handler : InitialConfigurator.DELAYED_HANDLER.getHandlers()) {
        if (handler instanceof AsyncHandler) {
            asyncHandler = (AsyncHandler) handler;
            Handler[] nestedHandlers = asyncHandler.getHandlers();
            boolean foundNestedConsoleHandler = false;
            for (Handler nestedHandler : nestedHandlers) {
                if (nestedHandler instanceof ConsoleHandler) {
                    foundNestedConsoleHandler = true;
                    break;
                }
            }
            if (!foundNestedConsoleHandler) {
                asyncHandler = null;
            }
        }
        if (asyncHandler != null) {
            break;
        }
    }
    if (asyncHandler != null) {
        try {
            // all we can do is wait because the thread that takes records off the queue is a daemon thread and there is no way to interact with its lifecycle
            Thread.sleep(200);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) SignalHandler(sun.misc.SignalHandler) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 4 with AsyncHandler

use of org.jboss.logmanager.handlers.AsyncHandler in project quarkus by quarkusio.

the class LoggingSetupRecorder method createAsyncHandler.

private static AsyncHandler createAsyncHandler(AsyncConfig asyncConfig, Level level, Handler handler) {
    final AsyncHandler asyncHandler = new AsyncHandler(asyncConfig.queueLength);
    asyncHandler.setOverflowAction(asyncConfig.overflow);
    asyncHandler.addHandler(handler);
    asyncHandler.setLevel(level);
    return asyncHandler;
}
Also used : AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler)

Example 5 with AsyncHandler

use of org.jboss.logmanager.handlers.AsyncHandler in project quarkus by quarkusio.

the class AsyncFileHandlerTest method asyncFileHandlerConfigurationTest.

@Test
public void asyncFileHandlerConfigurationTest() {
    Handler handler = getHandler(AsyncHandler.class);
    assertThat(handler.getLevel()).isEqualTo(Level.INFO);
    AsyncHandler asyncHandler = (AsyncHandler) handler;
    assertThat(asyncHandler.getHandlers()).isNotEmpty();
    assertThat(asyncHandler.getQueueLength()).isEqualTo(1024);
    assertThat(asyncHandler.getOverflowAction()).isEqualTo(AsyncHandler.OverflowAction.BLOCK);
    Handler nestedFileHandler = Arrays.stream(asyncHandler.getHandlers()).filter(h -> (h instanceof FileHandler)).findFirst().get();
    FileHandler fileHandler = (FileHandler) nestedFileHandler;
    assertThat(fileHandler.getLevel()).isEqualTo(Level.INFO);
}
Also used : AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) Handler(java.util.logging.Handler) LoggingTestsHelper.getHandler(io.quarkus.logging.LoggingTestsHelper.getHandler) AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) FileHandler(org.jboss.logmanager.handlers.FileHandler) FileHandler(org.jboss.logmanager.handlers.FileHandler) Test(org.junit.jupiter.api.Test) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest)

Aggregations

AsyncHandler (org.jboss.logmanager.handlers.AsyncHandler)5 Handler (java.util.logging.Handler)4 LoggingTestsHelper.getHandler (io.quarkus.logging.LoggingTestsHelper.getHandler)3 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)3 Test (org.junit.jupiter.api.Test)3 ConsoleHandler (java.util.logging.ConsoleHandler)1 ConsoleHandler (org.jboss.logmanager.handlers.ConsoleHandler)1 FileHandler (org.jboss.logmanager.handlers.FileHandler)1 SyslogHandler (org.jboss.logmanager.handlers.SyslogHandler)1 SignalHandler (sun.misc.SignalHandler)1