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();
}
}
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();
}
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();
}
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();
}
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("--->");
}
Aggregations