Search in sources :

Example 21 with AsyncLoggingEventAppenderFactory

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

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

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

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

Example 25 with AsyncLoggingEventAppenderFactory

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

the class LogbackClassicRequestLogFactory 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 LevelFilterFactory<ILoggingEvent> levelFilterFactory = new NullLevelFilterFactory<>();
    final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
    final LayoutFactory<ILoggingEvent> layoutFactory = (c, tz) -> new RequestLogLayout(c);
    final AppenderAttachableImpl<ILoggingEvent> attachable = new AppenderAttachableImpl<>();
    for (AppenderFactory<ILoggingEvent> appender : appenders) {
        attachable.addAppender(appender.build(context, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }
    return new CustomRequestLog(new DropwizardSlf4jRequestLogWriter(attachable), ClassicLogFormat.pattern(timeZone));
}
Also used : Context(ch.qos.logback.core.Context) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ConsoleAppenderFactory(io.dropwizard.logging.ConsoleAppenderFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerFactory(org.slf4j.LoggerFactory) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) Valid(javax.validation.Valid) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) RequestLogFactory(io.dropwizard.request.logging.RequestLogFactory) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) CoreConstants(ch.qos.logback.core.CoreConstants) PatternLayoutBase(ch.qos.logback.core.pattern.PatternLayoutBase) AppenderAttachableImpl(ch.qos.logback.core.spi.AppenderAttachableImpl) RequestLog(org.eclipse.jetty.server.RequestLog) LayoutFactory(io.dropwizard.logging.layout.LayoutFactory) TimeZone(java.util.TimeZone) AppenderFactory(io.dropwizard.logging.AppenderFactory) LevelFilterFactory(io.dropwizard.logging.filter.LevelFilterFactory) NotNull(javax.validation.constraints.NotNull) List(java.util.List) Logger(ch.qos.logback.classic.Logger) CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) AsyncAppenderFactory(io.dropwizard.logging.async.AsyncAppenderFactory) Collections(java.util.Collections) CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) AppenderAttachableImpl(ch.qos.logback.core.spi.AppenderAttachableImpl) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)

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