Search in sources :

Example 1 with AsyncLoggingEventAppenderFactory

use of io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory 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();
        }
    }
}
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)

Example 2 with AsyncLoggingEventAppenderFactory

use of io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory in project dropwizard by dropwizard.

the class FileAppenderFactoryTest method includesCallerData.

@Test
void includesCallerData() {
    FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
    fileAppenderFactory.setArchive(false);
    assertThat(fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory())).isInstanceOfSatisfying(AsyncAppender.class, asyncAppender -> assertThat(asyncAppender.isIncludeCallerData()).isFalse());
    fileAppenderFactory.setIncludeCallerData(true);
    assertThat(fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory())).isInstanceOfSatisfying(AsyncAppender.class, asyncAppender -> assertThat(asyncAppender.isIncludeCallerData()).isTrue());
}
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 3 with AsyncLoggingEventAppenderFactory

use of io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory in project dropwizard by dropwizard.

the class FileAppenderFactoryTest method isNeverBlock.

@Test
void isNeverBlock() {
    FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
    fileAppenderFactory.setArchive(false);
    fileAppenderFactory.setNeverBlock(true);
    assertThat(fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory())).isInstanceOfSatisfying(AsyncAppender.class, asyncAppender -> assertThat(asyncAppender.isNeverBlock()).isTrue());
}
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 4 with AsyncLoggingEventAppenderFactory

use of io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory 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())));
}
Also used : SizeAndTimeBasedRollingPolicy(ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) SizeBasedTriggeringPolicy(ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy) ConstraintViolations(io.dropwizard.validation.ConstraintViolations) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) OutputStreamAppender(ch.qos.logback.core.OutputStreamAppender) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) ConfigurationException(io.dropwizard.configuration.ConfigurationException) FileAppender(ch.qos.logback.core.FileAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) Appender(ch.qos.logback.core.Appender) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Jackson(io.dropwizard.jackson.Jackson) AsyncAppender(ch.qos.logback.classic.AsyncAppender) YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) BaseValidator(io.dropwizard.validation.BaseValidator) Path(java.nio.file.Path) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) ConfigurationValidationException(io.dropwizard.configuration.ConfigurationValidationException) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DiscoverableSubtypeResolver(io.dropwizard.jackson.DiscoverableSubtypeResolver) Validator(javax.validation.Validator) ResourceConfigurationSourceProvider(io.dropwizard.configuration.ResourceConfigurationSourceProvider) IOException(java.io.IOException) Field(java.lang.reflect.Field) Test(org.junit.jupiter.api.Test) DataSize(io.dropwizard.util.DataSize) FileSize(ch.qos.logback.core.util.FileSize) Logger(ch.qos.logback.classic.Logger) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) TempDir(org.junit.jupiter.api.io.TempDir) DateTimeFormatter(java.time.format.DateTimeFormatter) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) FixedWindowRollingPolicy(ch.qos.logback.core.rolling.FixedWindowRollingPolicy) Field(java.lang.reflect.Field) 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 5 with AsyncLoggingEventAppenderFactory

use of io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory in project dropwizard by dropwizard.

the class SyslogAppenderFactoryTest method appenderNameIsSet.

@Test
void appenderNameIsSet() {
    final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    final SyslogAppenderFactory appenderFactory = new SyslogAppenderFactory();
    final Appender<ILoggingEvent> appender = appenderFactory.build(root.getLoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(appender.getName()).isEqualTo("async-syslog-appender");
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) 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)25 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)24 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)23 Test (org.junit.jupiter.api.Test)19 LoggerContext (ch.qos.logback.classic.LoggerContext)15 Logger (ch.qos.logback.classic.Logger)13 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)8 AsyncAppender (ch.qos.logback.classic.AsyncAppender)5 Appender (ch.qos.logback.core.Appender)3 Test (org.junit.Test)3 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)2 PatternLayoutBase (ch.qos.logback.core.pattern.PatternLayoutBase)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 AsyncAppenderFactory (io.dropwizard.logging.async.AsyncAppenderFactory)2 ThresholdLevelFilterFactory (io.dropwizard.logging.filter.ThresholdLevelFilterFactory)2 BaseValidator (io.dropwizard.validation.BaseValidator)2 Field (java.lang.reflect.Field)2