Search in sources :

Example 1 with NullLevelFilterFactory

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;
}
Also used : LogbackAccessRequestLayoutFactory(io.dropwizard.request.logging.layout.LogbackAccessRequestLayoutFactory) AsyncAccessEventAppenderFactory(io.dropwizard.request.logging.async.AsyncAccessEventAppenderFactory) IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 2 with NullLevelFilterFactory

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();
        }
    }
}
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 3 with NullLevelFilterFactory

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())));
}
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 4 with NullLevelFilterFactory

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("--->")));
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiscoverableSubtypeResolver(io.dropwizard.jackson.DiscoverableSubtypeResolver) LoggerFactory(org.slf4j.LoggerFactory) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.jupiter.api.Test) SyslogAppender(ch.qos.logback.classic.net.SyslogAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) Logger(ch.qos.logback.classic.Logger) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Locale(java.util.Locale) Appender(ch.qos.logback.core.Appender) AsyncAppender(ch.qos.logback.classic.AsyncAppender) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) SyslogAppender(ch.qos.logback.classic.net.SyslogAppender) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.jupiter.api.Test)

Example 5 with NullLevelFilterFactory

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+\\].+");
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) AsyncAppender(ch.qos.logback.classic.AsyncAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) SyslogAppender(ch.qos.logback.classic.net.SyslogAppender) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Aggregations

NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)9 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)8 LoggerContext (ch.qos.logback.classic.LoggerContext)7 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)7 Logger (ch.qos.logback.classic.Logger)6 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)6 Test (org.junit.jupiter.api.Test)6 AsyncAppender (ch.qos.logback.classic.AsyncAppender)5 Appender (ch.qos.logback.core.Appender)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)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 BaseValidator (io.dropwizard.validation.BaseValidator)2 Field (java.lang.reflect.Field)2 TimeZone (java.util.TimeZone)2 LoggerFactory (org.slf4j.LoggerFactory)2