Search in sources :

Example 1 with AsyncAppender

use of ch.qos.logback.classic.AsyncAppender in project dropwizard by dropwizard.

the class DefaultLoggingFactory method stop.

@Override
public void stop() {
    // Should acquire the lock to avoid concurrent listener changes
    CHANGE_LOGGER_CONTEXT_LOCK.lock();
    try {
        // We need to go through a list of appenders and locate the async ones,
        // as those could have messages left to write. Since there is no flushing
        // mechanism built into logback, we wait for a short period of time before
        // giving up that the appender will be completely flushed.
        final Logger logger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
        final ArrayList<Appender<ILoggingEvent>> appenders = Lists.newArrayList(logger.iteratorForAppenders());
        for (Appender<ILoggingEvent> appender : appenders) {
            if (appender instanceof AsyncAppender) {
                flushAppender((AsyncAppender) appender);
            }
        }
    } catch (InterruptedException ignored) {
        // If the thread waiting for the logs to be flushed is aborted then
        // user clearly wants the application to quit now, so stop trying
        // to flush any appenders
        Thread.currentThread().interrupt();
    } finally {
        CHANGE_LOGGER_CONTEXT_LOCK.unlock();
    }
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) Appender(ch.qos.logback.core.Appender) AsyncAppender(ch.qos.logback.classic.AsyncAppender) InstrumentedAppender(com.codahale.metrics.logback.InstrumentedAppender) AsyncAppender(ch.qos.logback.classic.AsyncAppender) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 2 with AsyncAppender

use of ch.qos.logback.classic.AsyncAppender in project dropwizard by dropwizard.

the class ConsoleAppenderFactoryTest method includesCallerData.

@Test
public void includesCallerData() {
    ConsoleAppenderFactory<ILoggingEvent> consoleAppenderFactory = new ConsoleAppenderFactory<>();
    AsyncAppender asyncAppender = (AsyncAppender) consoleAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(asyncAppender.isIncludeCallerData()).isFalse();
    consoleAppenderFactory.setIncludeCallerData(true);
    asyncAppender = (AsyncAppender) consoleAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(asyncAppender.isIncludeCallerData()).isTrue();
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) AsyncAppender(ch.qos.logback.classic.AsyncAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 3 with AsyncAppender

use of ch.qos.logback.classic.AsyncAppender in project dropwizard by dropwizard.

the class ConsoleAppenderFactoryTest method isNeverBlock.

@Test
public void isNeverBlock() throws Exception {
    ConsoleAppenderFactory<ILoggingEvent> consoleAppenderFactory = new ConsoleAppenderFactory<>();
    consoleAppenderFactory.setNeverBlock(true);
    AsyncAppender asyncAppender = (AsyncAppender) consoleAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(asyncAppender.isNeverBlock()).isTrue();
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) AsyncAppender(ch.qos.logback.classic.AsyncAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 4 with AsyncAppender

use of ch.qos.logback.classic.AsyncAppender in project dropwizard by dropwizard.

the class FileAppenderFactoryTest method isNeverBlock.

@Test
public void isNeverBlock() throws Exception {
    FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
    fileAppenderFactory.setArchive(false);
    fileAppenderFactory.setNeverBlock(true);
    AsyncAppender asyncAppender = (AsyncAppender) fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(asyncAppender.isNeverBlock()).isTrue();
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) AsyncAppender(ch.qos.logback.classic.AsyncAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 5 with AsyncAppender

use of ch.qos.logback.classic.AsyncAppender in project dropwizard by dropwizard.

the class SyslogAppenderFactoryTest method stackTracePatternCanBeSet.

@Test
public void stackTracePatternCanBeSet() throws Exception {
    final SyslogAppenderFactory syslogAppenderFactory = new SyslogAppenderFactory();
    syslogAppenderFactory.setStackTracePrefix("--->");
    final AsyncAppender wrapper = (AsyncAppender) syslogAppenderFactory.build(new LoggerContext(), "MyApplication", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(((SyslogAppender) wrapper.getAppender("syslog-appender")).getStackTracePattern()).isEqualTo("--->");
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) AsyncAppender(ch.qos.logback.classic.AsyncAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) SyslogAppender(ch.qos.logback.classic.net.SyslogAppender) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Aggregations

AsyncAppender (ch.qos.logback.classic.AsyncAppender)12 LoggerContext (ch.qos.logback.classic.LoggerContext)11 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)11 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)11 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)11 Test (org.junit.Test)11 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)10 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)2 Logger (ch.qos.logback.classic.Logger)1 Appender (ch.qos.logback.core.Appender)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 FileSize (ch.qos.logback.core.util.FileSize)1 InstrumentedAppender (com.codahale.metrics.logback.InstrumentedAppender)1 Field (java.lang.reflect.Field)1