io.dropwizard.logging.AbstractOutputStreamAppenderFactory Maven / Gradle / Ivy
package io.dropwizard.logging;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.Appender;
import ch.qos.logback.core.OutputStreamAppender;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
import ch.qos.logback.core.spi.DeferredProcessingAware;
import io.dropwizard.logging.async.AsyncAppenderFactory;
import io.dropwizard.logging.filter.LevelFilterFactory;
import io.dropwizard.logging.layout.LayoutFactory;
/**
* A base implementation of {@link AppenderFactory} producing an appender based on {@link OutputStreamAppender}.
*/
public abstract class AbstractOutputStreamAppenderFactory
extends AbstractAppenderFactory {
protected abstract OutputStreamAppender appender(LoggerContext context);
@Override
public Appender build(LoggerContext context, String applicationName, LayoutFactory layoutFactory,
LevelFilterFactory levelFilterFactory, AsyncAppenderFactory asyncAppenderFactory) {
final OutputStreamAppender appender = appender(context);
final LayoutWrappingEncoder layoutEncoder = new LayoutWrappingEncoder<>();
layoutEncoder.setLayout(buildLayout(context, layoutFactory));
appender.setEncoder(layoutEncoder);
appender.addFilter(levelFilterFactory.build(threshold));
getFilterFactories().forEach(f -> appender.addFilter(f.build()));
appender.start();
return wrapAsync(appender, asyncAppenderFactory);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy