use of io.dropwizard.logging.filter.NullLevelFilterFactory in project dropwizard by dropwizard.
the class LogbackAccessRequestLogFactory method build.
@Override
public RequestLog build(String name) {
final Logger logger = (Logger) LoggerFactory.getLogger("http.request");
logger.setAdditive(false);
final LoggerContext context = logger.getLoggerContext();
final LogbackAccessRequestLog requestLog = new LogbackAccessRequestLog();
final LevelFilterFactory<IAccessEvent> levelFilterFactory = new NullLevelFilterFactory<>();
final AsyncAppenderFactory<IAccessEvent> asyncAppenderFactory = new AsyncAccessEventAppenderFactory();
final LayoutFactory<IAccessEvent> layoutFactory = new LogbackAccessRequestLayoutFactory();
for (AppenderFactory<IAccessEvent> output : appenders) {
requestLog.addAppender(output.build(context, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
}
return requestLog;
}
use of io.dropwizard.logging.filter.NullLevelFilterFactory in project dropwizard by dropwizard.
the class FileAppenderFactoryTest method appenderNameIsSet.
@Test
void appenderNameIsSet(@TempDir Path tempDir) {
final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
final FileAppenderFactory<ILoggingEvent> appenderFactory = new FileAppenderFactory<>();
appenderFactory.setArchivedLogFilenamePattern(tempDir.resolve("example-%d.log.gz").toString());
Appender<ILoggingEvent> appender = null;
try {
appender = appenderFactory.build(root.getLoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
assertThat(appender.getName()).isEqualTo("async-file-appender");
} finally {
if (appender != null) {
appender.stop();
}
}
}
use of io.dropwizard.logging.filter.NullLevelFilterFactory in project dropwizard by dropwizard.
the class FileAppenderFactoryTest method isImmediateFlushed.
@Test
void isImmediateFlushed() throws Exception {
FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
fileAppenderFactory.setArchive(false);
Field isImmediateFlushField = OutputStreamAppender.class.getDeclaredField("immediateFlush");
isImmediateFlushField.setAccessible(true);
fileAppenderFactory.setImmediateFlush(false);
assertThat(fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory())).isInstanceOfSatisfying(AsyncAppender.class, asyncAppender -> assertThat(asyncAppender).extracting(appender -> appender.getAppender("file-appender")).satisfies(fileAppender -> assertThat(isImmediateFlushField.get(fileAppender)).isEqualTo(fileAppenderFactory.isImmediateFlush())));
fileAppenderFactory.setImmediateFlush(true);
assertThat(fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory())).isInstanceOfSatisfying(AsyncAppender.class, asyncAppender -> assertThat(asyncAppender).extracting(appender -> appender.getAppender("file-appender")).satisfies(fileAppender -> assertThat(isImmediateFlushField.get(fileAppender)).isEqualTo(fileAppenderFactory.isImmediateFlush())));
}
use of io.dropwizard.logging.filter.NullLevelFilterFactory in project dropwizard by dropwizard.
the class SyslogAppenderFactoryTest method stackTracePatternCanBeSet.
@Test
void stackTracePatternCanBeSet() {
final SyslogAppenderFactory syslogAppenderFactory = new SyslogAppenderFactory();
syslogAppenderFactory.setStackTracePrefix("--->");
assertThat(syslogAppenderFactory.build(new LoggerContext(), "MyApplication", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory())).isInstanceOfSatisfying(AsyncAppender.class, asyncAppender -> assertThat(asyncAppender.getAppender("syslog-appender")).isInstanceOfSatisfying(SyslogAppender.class, syslogAppender -> assertThat(syslogAppender.getStackTracePattern()).isEqualTo("--->")));
}
use of io.dropwizard.logging.filter.NullLevelFilterFactory in project dropwizard by dropwizard.
the class SyslogAppenderFactoryTest method patternIncludesAppNameAndPid.
@Test
public void patternIncludesAppNameAndPid() throws Exception {
final AsyncAppender wrapper = (AsyncAppender) new SyslogAppenderFactory().build(new LoggerContext(), "MyApplication", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
assertThat(((SyslogAppender) wrapper.getAppender("syslog-appender")).getSuffixPattern()).matches("^MyApplication\\[\\d+\\].+");
}
Aggregations