use of io.dropwizard.logging.layout.DropwizardLayoutFactory in project dropwizard by dropwizard.
the class FileAppenderFactoryTest method testAppenderIsStarted.
@Test
void testAppenderIsStarted(@TempDir Path tempDir) {
FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
fileAppenderFactory.setCurrentLogFilename(tempDir.resolve("application.log").toString());
fileAppenderFactory.setArchive(true);
fileAppenderFactory.setArchivedFileCount(20);
fileAppenderFactory.setArchivedLogFilenamePattern("application-%i.log");
fileAppenderFactory.setMaxFileSize(DataSize.megabytes(500));
fileAppenderFactory.setImmediateFlush(false);
fileAppenderFactory.setThreshold("ERROR");
Appender<ILoggingEvent> appender = fileAppenderFactory.build(new LoggerContext(), "test-app", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
assertThat(appender.isStarted()).isTrue();
appender.stop();
assertThat(appender.isStarted()).isFalse();
}
use of io.dropwizard.logging.layout.DropwizardLayoutFactory in project dropwizard by dropwizard.
the class FileAppenderFactoryTest method overrideBufferSize.
@Test
void overrideBufferSize() throws NoSuchFieldException, IllegalAccessException {
FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
fileAppenderFactory.setArchive(false);
fileAppenderFactory.setBufferSize(DataSize.kibibytes(256));
AsyncAppender asyncAppender = (AsyncAppender) fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
final Appender<ILoggingEvent> fileAppender = asyncAppender.getAppender("file-appender");
assertThat(fileAppender).isInstanceOf(FileAppender.class);
final Field bufferSizeField = FileAppender.class.getDeclaredField("bufferSize");
bufferSizeField.setAccessible(true);
assertThat(bufferSizeField.get(fileAppender)).isInstanceOfSatisfying(FileSize.class, bufferSize -> assertThat(bufferSize.getSize()).isEqualTo(fileAppenderFactory.getBufferSize().toBytes()));
}
use of io.dropwizard.logging.layout.DropwizardLayoutFactory in project dropwizard by dropwizard.
the class FileAppenderFactoryTest method isNotNeverBlock.
@Test
void isNotNeverBlock() {
FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
fileAppenderFactory.setArchive(false);
fileAppenderFactory.setNeverBlock(false);
assertThat(fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory())).isInstanceOfSatisfying(AsyncAppender.class, asyncAppender -> assertThat(asyncAppender.isNeverBlock()).isFalse());
}
use of io.dropwizard.logging.layout.DropwizardLayoutFactory in project dropwizard by dropwizard.
the class FileAppenderFactoryTest method appenderContextIsSet.
@Test
void appenderContextIsSet(@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.getContext()).isEqualTo(root.getLoggerContext());
} finally {
if (appender != null) {
appender.stop();
}
}
}
Aggregations