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>
AnAppenderFactoryimplementation which provides an appender that writes events to a file, archiving older files as it goes. Configuration Parameters:Name Default Description typeREQUIRED The appender type. Must be file.thresholdALLThe lowest level of events to write to the file. currentLogFilenameREQUIRED The filename where current events are logged. archivetrueWhether or not to archive old events in separate files. archivedLogFilenamePatternREQUIRED if archiveistrue.The filename pattern for archived files. If maxFileSizeis specified, rollover is size-based, and the pattern must contain%ifor 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-ddform. If the pattern ends with.gzor.zip, files will be compressed as they are archived.archivedFileCount5The 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. timeZoneUTCThe time zone to which event timestamps will be converted. logFormatthe default format The Logback pattern with which events will be formatted. See the Logback documentation for details. bufferSize8KiB 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. immediateFlushtrueIf 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)intgetArchivedFileCount()@Nullable StringgetArchivedLogFilenamePattern()DataSizegetBufferSize()@Nullable StringgetCurrentLogFilename()@Nullable DataSizegetMaxFileSize()@Nullable DataSizegetTotalSizeCap()Returns the total size threshold at which archived log files will be removed.booleanisArchive()booleanisImmediateFlush()booleanisMaxFileSizeSettingSpecified()booleanisTotalSizeCapValid()Returns a boolean indicating whether thetotalSizeCapproperty will be used.booleanisValidArchiveConfiguration()booleanisValidFileConfiguration()booleanisValidForMaxFileSizeSetting()voidsetArchive(boolean archive)voidsetArchivedFileCount(int archivedFileCount)voidsetArchivedLogFilenamePattern(String archivedLogFilenamePattern)voidsetBufferSize(DataSize bufferSize)voidsetCurrentLogFilename(@Nullable String currentLogFilename)voidsetImmediateFlush(boolean immediateFlush)voidsetMaxFileSize(@Nullable DataSize maxFileSize)voidsetTotalSizeCap(@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 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)
-
-