Package io.dropwizard.logging.common
Class FileAppenderFactory<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>
- All Implemented Interfaces:
io.dropwizard.jackson.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:
-
Field Summary
Fields inherited from class io.dropwizard.logging.common.AbstractAppenderFactory
layout, logFormat, threshold, timeZone -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ch.qos.logback.core.OutputStreamAppender<E>appender(ch.qos.logback.classic.LoggerContext context) protected ch.qos.logback.core.FileAppender<E>buildAppender(ch.qos.logback.classic.LoggerContext context) int@Nullable Stringio.dropwizard.util.DataSize@Nullable String@Nullable io.dropwizard.util.DataSize@Nullable io.dropwizard.util.DataSizeReturns the total size threshold at which archived log files will be removed.booleanbooleanbooleanbooleanReturns a boolean indicating whether thetotalSizeCapproperty will be used.booleanbooleanbooleanvoidsetArchive(boolean archive) voidsetArchivedFileCount(int archivedFileCount) voidsetArchivedLogFilenamePattern(String archivedLogFilenamePattern) voidsetBufferSize(io.dropwizard.util.DataSize bufferSize) voidsetCurrentLogFilename(@Nullable String currentLogFilename) voidsetImmediateFlush(boolean immediateFlush) voidsetMaxFileSize(@Nullable io.dropwizard.util.DataSize maxFileSize) voidsetTotalSizeCap(@Nullable io.dropwizard.util.DataSize totalSizeCap) Sets the total size threshold at which archived log files will be removed.Methods inherited from class io.dropwizard.logging.common.AbstractOutputStreamAppenderFactory
buildMethods 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
-
Constructor Details
-
FileAppenderFactory
public FileAppenderFactory()
-
-
Method Details
-
getCurrentLogFilename
-
setCurrentLogFilename
-
isArchive
public boolean isArchive() -
setArchive
public void setArchive(boolean archive) -
getArchivedLogFilenamePattern
-
setArchivedLogFilenamePattern
-
getArchivedFileCount
public int getArchivedFileCount() -
setArchivedFileCount
public void setArchivedFileCount(int archivedFileCount) -
getMaxFileSize
public @Nullable io.dropwizard.util.DataSize getMaxFileSize() -
setMaxFileSize
public void setMaxFileSize(@Nullable io.dropwizard.util.DataSize maxFileSize) -
getTotalSizeCap
public @Nullable io.dropwizard.util.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 io.dropwizard.util.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 io.dropwizard.util.DataSize getBufferSize() -
setBufferSize
public void setBufferSize(io.dropwizard.util.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 thetotalSizeCapproperty 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:
appenderin classAbstractOutputStreamAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>
-
buildAppender
protected ch.qos.logback.core.FileAppender<E> buildAppender(ch.qos.logback.classic.LoggerContext context)
-