Search in sources :

Example 21 with DropwizardLayoutFactory

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();
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.jupiter.api.Test)

Example 22 with DropwizardLayoutFactory

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()));
}
Also used : Field(java.lang.reflect.Field) 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.jupiter.api.Test)

Example 23 with DropwizardLayoutFactory

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());
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.jupiter.api.Test)

Example 24 with DropwizardLayoutFactory

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();
        }
    }
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.jupiter.api.Test)

Aggregations

AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)24 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)24 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)22 Test (org.junit.jupiter.api.Test)19 LoggerContext (ch.qos.logback.classic.LoggerContext)14 Logger (ch.qos.logback.classic.Logger)12 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)7 AsyncAppender (ch.qos.logback.classic.AsyncAppender)5 Appender (ch.qos.logback.core.Appender)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Test (org.junit.Test)3 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)2 ResourceConfigurationSourceProvider (io.dropwizard.configuration.ResourceConfigurationSourceProvider)2 YamlConfigurationFactory (io.dropwizard.configuration.YamlConfigurationFactory)2 DiscoverableSubtypeResolver (io.dropwizard.jackson.DiscoverableSubtypeResolver)2 Jackson (io.dropwizard.jackson.Jackson)2 ThresholdLevelFilterFactory (io.dropwizard.logging.filter.ThresholdLevelFilterFactory)2 BaseValidator (io.dropwizard.validation.BaseValidator)2 Field (java.lang.reflect.Field)2 LoggerFactory (org.slf4j.LoggerFactory)2