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

  • All Implemented Interfaces:
    Discoverable, AppenderFactory<E>

    public class FileAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>
    extends AbstractOutputStreamAppenderFactory<E>
    An AppenderFactory implementation which provides an appender that writes events to a file, archiving older files as it goes.

    Configuration Parameters:

    Name Default Description
    type REQUIRED The appender type. Must be file.
    threshold ALL The lowest level of events to write to the file.
    currentLogFilename REQUIRED The filename where current events are logged.
    archive true Whether or not to archive old events in separate files.
    archivedLogFilenamePattern REQUIRED if archive is true. The filename pattern for archived files. If maxFileSize is specified, rollover is size-based, and the pattern must contain %i for an integer index of the archived file. Otherwise rollover is date-based, and the pattern must contain %d, which is replaced with the date in yyyy-MM-dd form. If the pattern ends with .gz or .zip, files will be compressed as they are archived.
    archivedFileCount 5 The number of archived files to keep. Must be greater than or equal to 0. Zero is a special value signifying to keep infinite logs (use with caution)
    maxFileSize (unlimited) The maximum size of the currently active file before a rollover is triggered. The value can be expressed with SI and IEC prefixes, see DataSizeUnit. Examples include 100MiB, 1GiB, 1TiB. Sizes can also be spelled out, such as 100 mebibytes, 1 gibibyte, 1 tebibyte.
    totalSizeCap (unlimited) Controls the total size of all files. Oldest archives are deleted asynchronously when the total size cap is exceeded.
    timeZone UTC The time zone to which event timestamps will be converted.
    logFormat the default format The Logback pattern with which events will be formatted. See the Logback documentation for details.
    bufferSize 8KiB The buffer size of the underlying FileAppender (setting added in logback 1.1.10). Increasing this from the default of 8KiB to 256KiB is reported to significantly reduce thread contention.
    immediateFlush true If set to true, log events will be immediately flushed to disk. Immediate flushing is safer, but it degrades logging throughput. See the Logback documentation for details.
    See Also:
    AbstractAppenderFactory
    • Constructor Detail

      • FileAppenderFactory

        public FileAppenderFactory()
    • Method Detail

      • getCurrentLogFilename

        public @Nullable String getCurrentLogFilename()
      • setCurrentLogFilename

        public void setCurrentLogFilename​(@Nullable String currentLogFilename)
      • isArchive

        public boolean isArchive()
      • setArchive

        public void setArchive​(boolean archive)
      • getArchivedLogFilenamePattern

        public @Nullable String getArchivedLogFilenamePattern()
      • setArchivedLogFilenamePattern

        public void setArchivedLogFilenamePattern​(String archivedLogFilenamePattern)
      • getArchivedFileCount

        public int getArchivedFileCount()
      • setArchivedFileCount

        public void setArchivedFileCount​(int archivedFileCount)
      • getMaxFileSize

        public @Nullable DataSize getMaxFileSize()
      • setMaxFileSize

        public void setMaxFileSize​(@Nullable DataSize maxFileSize)
      • getTotalSizeCap

        public @Nullable DataSize getTotalSizeCap()
        Returns the total size threshold at which archived log files will be removed. A zero value means there is limit.
        Since:
        2.0
      • setTotalSizeCap

        public void setTotalSizeCap​(@Nullable DataSize totalSizeCap)
        Sets the total size threshold at which archived log files will be removed. A zero value means there is limit.
        Since:
        2.0
      • getBufferSize

        public DataSize getBufferSize()
      • setBufferSize

        public void setBufferSize​(DataSize bufferSize)
      • isImmediateFlush

        public boolean isImmediateFlush()
      • setImmediateFlush

        public void setImmediateFlush​(boolean immediateFlush)
      • isTotalSizeCapValid

        @ValidationMethod(message="totalSizeCap has no effect when using maxFileSize and an archivedLogFilenamePattern without %d, as archivedFileCount implicitly controls the total size cap")
        public boolean isTotalSizeCapValid()
        Returns a boolean indicating whether the totalSizeCap property will be used.
        Since:
        2.0
      • isValidArchiveConfiguration

        @ValidationMethod(message="must have archivedLogFilenamePattern if archive is true")
        public boolean isValidArchiveConfiguration()
      • isValidForMaxFileSizeSetting

        @ValidationMethod(message="when specifying maxFileSize, archivedLogFilenamePattern must contain %i")
        public boolean isValidForMaxFileSizeSetting()
      • isMaxFileSizeSettingSpecified

        @ValidationMethod(message="when archivedLogFilenamePattern contains %i, maxFileSize must be specified")
        public boolean isMaxFileSizeSettingSpecified()
      • isValidFileConfiguration

        @ValidationMethod(message="currentLogFilename can only be null when archiving is enabled")
        public boolean isValidFileConfiguration()
      • appender

        protected ch.qos.logback.core.OutputStreamAppender<E> appender​(ch.qos.logback.classic.LoggerContext context)
        Specified by:
        appender in class AbstractOutputStreamAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>
      • buildAppender

        protected ch.qos.logback.core.FileAppender<E> buildAppender​(ch.qos.logback.classic.LoggerContext context)