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

java.lang.Object
io.dropwizard.logging.common.AbstractAppenderFactory<E>
io.dropwizard.logging.common.AbstractOutputStreamAppenderFactory<E>
io.dropwizard.logging.common.FileAppenderFactory<E>
org.kiwiproject.beta.dropwizard.DefaultingFileAppenderFactory<E>
All Implemented Interfaces:
io.dropwizard.jackson.Discoverable, io.dropwizard.logging.common.AppenderFactory<E>

@Beta public class DefaultingFileAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware> extends io.dropwizard.logging.common.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.common.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.common.AbstractAppenderFactory

    layout, logFormat, threshold, timeZone
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    ch.qos.logback.core.Appender<E>
    build(ch.qos.logback.classic.LoggerContext context, String applicationName, io.dropwizard.logging.common.layout.LayoutFactory<E> layoutFactory, io.dropwizard.logging.common.filter.LevelFilterFactory<E> levelFilterFactory, io.dropwizard.logging.common.async.AsyncAppenderFactory<E> asyncAppenderFactory)
     
    boolean
    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.common.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.common.AbstractAppenderFactory

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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultingFileAppenderFactory

      public DefaultingFileAppenderFactory()
  • Method Details

    • build

      public ch.qos.logback.core.Appender<E> build(ch.qos.logback.classic.LoggerContext context, String applicationName, io.dropwizard.logging.common.layout.LayoutFactory<E> layoutFactory, io.dropwizard.logging.common.filter.LevelFilterFactory<E> levelFilterFactory, io.dropwizard.logging.common.async.AsyncAppenderFactory<E> asyncAppenderFactory)
      Specified by:
      build in interface io.dropwizard.logging.common.AppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>
      Overrides:
      build in class io.dropwizard.logging.common.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.