public class FileAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware> extends AbstractOutputStreamAppenderFactory<E>
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. |
AbstractAppenderFactorylayout, logFormat, threshold, timeZone| Constructor and Description |
|---|
FileAppenderFactory() |
| Modifier and Type | Method and 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() |
String |
getArchivedLogFilenamePattern() |
DataSize |
getBufferSize() |
String |
getCurrentLogFilename() |
DataSize |
getMaxFileSize() |
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 the
totalSizeCap 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(String currentLogFilename) |
void |
setImmediateFlush(boolean immediateFlush) |
void |
setMaxFileSize(DataSize maxFileSize) |
void |
setTotalSizeCap(DataSize totalSizeCap)
Sets the total size threshold at which archived log files will be
removed.
|
buildbuildLayout, getDiscardingThreshold, getFilterFactories, getLayout, getLogFormat, getMessageRate, getQueueSize, getThreshold, getTimeZone, isIncludeCallerData, setDiscardingThreshold, setFilterFactories, setIncludeCallerData, setLayout, setLogFormat, setMessageRate, setNeverBlock, setQueueSize, setThreshold, setTimeZone, setTimeZone, wrapAsync, wrapAsyncpublic boolean isArchive()
public void setArchive(boolean archive)
public void setArchivedLogFilenamePattern(String archivedLogFilenamePattern)
public int getArchivedFileCount()
public void setArchivedFileCount(int archivedFileCount)
@Nullable public DataSize getTotalSizeCap()
public void setTotalSizeCap(@Nullable DataSize totalSizeCap)
public DataSize getBufferSize()
public void setBufferSize(DataSize bufferSize)
public boolean isImmediateFlush()
public void setImmediateFlush(boolean immediateFlush)
@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()
totalSizeCap property
will be used.@ValidationMethod(message="must have archivedLogFilenamePattern if archive is true") public boolean isValidArchiveConfiguration()
@ValidationMethod(message="when specifying maxFileSize, archivedLogFilenamePattern must contain %i") public boolean isValidForMaxFileSizeSetting()
@ValidationMethod(message="when archivedLogFilenamePattern contains %i, maxFileSize must be specified") public boolean isMaxFileSizeSettingSpecified()
@ValidationMethod(message="currentLogFilename can only be null when archiving is enabled") public boolean isValidFileConfiguration()
protected ch.qos.logback.core.OutputStreamAppender<E> appender(ch.qos.logback.classic.LoggerContext context)
appender in class AbstractOutputStreamAppenderFactory<E extends ch.qos.logback.core.spi.DeferredProcessingAware>protected ch.qos.logback.core.FileAppender<E> buildAppender(ch.qos.logback.classic.LoggerContext context)
Copyright © 2023. All rights reserved.