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:
Discoverable
,AppenderFactory<E>
public class FileAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware> extends AbstractOutputStreamAppenderFactory<E>
AnAppenderFactory
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
istrue
.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 inyyyy-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
-
-
Field Summary
-
Fields inherited from class io.dropwizard.logging.common.AbstractAppenderFactory
layout, logFormat, threshold, timeZone
-
-
Constructor Summary
Constructors Constructor Description FileAppenderFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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
getArchivedFileCount()
@Nullable String
getArchivedLogFilenamePattern()
DataSize
getBufferSize()
@Nullable String
getCurrentLogFilename()
@Nullable DataSize
getMaxFileSize()
@Nullable DataSize
getTotalSizeCap()
Returns the total size threshold at which archived log files will be removed.boolean
isArchive()
boolean
isImmediateFlush()
boolean
isMaxFileSizeSettingSpecified()
boolean
isTotalSizeCapValid()
Returns a boolean indicating whether thetotalSizeCap
property will be used.boolean
isValidArchiveConfiguration()
boolean
isValidFileConfiguration()
boolean
isValidForMaxFileSizeSetting()
void
setArchive(boolean archive)
void
setArchivedFileCount(int archivedFileCount)
void
setArchivedLogFilenamePattern(String archivedLogFilenamePattern)
void
setBufferSize(DataSize bufferSize)
void
setCurrentLogFilename(@Nullable String currentLogFilename)
void
setImmediateFlush(boolean immediateFlush)
void
setMaxFileSize(@Nullable DataSize maxFileSize)
void
setTotalSizeCap(@Nullable DataSize totalSizeCap)
Sets the total size threshold at which archived log files will be removed.-
Methods inherited from class io.dropwizard.logging.common.AbstractOutputStreamAppenderFactory
build
-
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
-
-
-
-
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 thetotalSizeCap
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 classAbstractOutputStreamAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>
-
buildAppender
protected ch.qos.logback.core.FileAppender<E> buildAppender(ch.qos.logback.classic.LoggerContext context)
-
-