Class DefaultingFileAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>

  • All Implemented Interfaces:
    io.dropwizard.jackson.Discoverable, io.dropwizard.logging.AppenderFactory<E>

    @Beta
    public class DefaultingFileAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>
    extends io.dropwizard.logging.FileAppenderFactory<E>
    A Dropwizard AppenderFactory implementation which extends FileAppenderFactory to provide default values for the current log file name, archive log file name pattern, and log format if they are not explicitly configured. Once the appender is built, these values can be retrieved from the factory instance using FileAppenderFactory.getCurrentLogFilename(), FileAppenderFactory.getArchivedLogFilenamePattern(), and AbstractAppenderFactory.getLogFormat().

    This factory provides the same properties available in FileAppenderFactory and one additional property which allows you to easily use the default Dropwizard log format instead of the one provided here.

    To use this in a Dropwizard application, the FQCN must be listed in a META-INF/services/io.dropwizard.logging.AppenderFactory file. Dropwizard already provides this file with its own implementations (in the dropwizard-logging JAR). This library also provides the same file with our implementation. These two files (and any others from other providers) must all be combined so the resulting file contains all implementations. We generally use the Maven Shade Plugin with the ServicesResourceTransformer to combine these service files.

    Last, in the logging configuration of your Dropwizard configuration file, you can add an appender of type rollingWithDefaults.

    See Also:
    AppenderFactory, FileAppenderFactory, RollingFileAppender
    • Field Summary

      • Fields inherited from class io.dropwizard.logging.AbstractAppenderFactory

        layout, logFormat, threshold, timeZone
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ch.qos.logback.core.Appender<E> build​(ch.qos.logback.classic.LoggerContext context, String applicationName, io.dropwizard.logging.layout.LayoutFactory<E> layoutFactory, io.dropwizard.logging.filter.LevelFilterFactory<E> levelFilterFactory, io.dropwizard.logging.async.AsyncAppenderFactory<E> asyncAppenderFactory)  
      boolean isUseDefaultDropwizardLogFormat()
      If true, uses the default Dropwizard log format provided by DropwizardLayout.
      void setUseDefaultDropwizardLogFormat​(boolean useDefaultDropwizardLogFormat)
      If true, uses the default Dropwizard log format provided by DropwizardLayout.
      • Methods inherited from class io.dropwizard.logging.FileAppenderFactory

        appender, buildAppender, getArchivedFileCount, getArchivedLogFilenamePattern, getBufferSize, getCurrentLogFilename, getMaxFileSize, getTotalSizeCap, isArchive, isImmediateFlush, isMaxFileSizeSettingSpecified, isTotalSizeCapValid, isValidArchiveConfiguration, isValidFileConfiguration, isValidForMaxFileSizeSetting, setArchive, setArchivedFileCount, setArchivedLogFilenamePattern, setBufferSize, setCurrentLogFilename, setImmediateFlush, setMaxFileSize, setTotalSizeCap
      • Methods inherited from class io.dropwizard.logging.AbstractAppenderFactory

        buildLayout, getDiscardingThreshold, getFilterFactories, getLayout, getLogFormat, getMessageRate, getQueueSize, getThreshold, getTimeZone, isIncludeCallerData, setDiscardingThreshold, setFilterFactories, setIncludeCallerData, setLayout, setLogFormat, setMessageRate, setNeverBlock, setQueueSize, setThreshold, setTimeZone, setTimeZone, wrapAsync, wrapAsync
    • Constructor Detail

      • DefaultingFileAppenderFactory

        public DefaultingFileAppenderFactory()
    • Method Detail

      • build

        public ch.qos.logback.core.Appender<E> build​(ch.qos.logback.classic.LoggerContext context,
                                                     String applicationName,
                                                     io.dropwizard.logging.layout.LayoutFactory<E> layoutFactory,
                                                     io.dropwizard.logging.filter.LevelFilterFactory<E> levelFilterFactory,
                                                     io.dropwizard.logging.async.AsyncAppenderFactory<E> asyncAppenderFactory)
        Specified by:
        build in interface io.dropwizard.logging.AppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>
        Overrides:
        build in class io.dropwizard.logging.AbstractOutputStreamAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>
      • isUseDefaultDropwizardLogFormat

        public boolean isUseDefaultDropwizardLogFormat()
        If true, uses the default Dropwizard log format provided by DropwizardLayout.
      • setUseDefaultDropwizardLogFormat

        public void setUseDefaultDropwizardLogFormat​(boolean useDefaultDropwizardLogFormat)
        If true, uses the default Dropwizard log format provided by DropwizardLayout.