public class RollingFileAppender extends FileAppender
AppenderSkeleton.NoOpErrorHandler| Modifier and Type | Field and Description |
|---|---|
protected int |
maxBackupIndex
There is one backup file by default.
|
protected long |
maxFileSize
The default maximum file size is 10MB.
|
bufferedIO, bufferSize, fileAppend, fileNameencoding, immediateFlush, qwclosed, errorHandler, headFilter, layout, name, tailFilter, threshold| Constructor and Description |
|---|
RollingFileAppender()
The default constructor simply calls its
parents constructor. |
RollingFileAppender(Layout layout,
String filename)
Constructs a FileAppender and open the file designated by
filename. |
RollingFileAppender(Layout layout,
String filename,
boolean append)
Constructs a RollingFileAppender and open the file designated by
filename. |
| Modifier and Type | Method and Description |
|---|---|
int |
getMaxBackupIndex()
Gets the value of the MaxBackupIndex option.
|
long |
getMaximumFileSize()
Gets the maximum size that the output file is allowed to reach before being rolled over to backup files.
|
void |
rollOver()
Implements the usual roll over behaviour.
|
void |
setFile(String fileName,
boolean append,
boolean bufferedIO,
int bufferSize)
Sets and opens the file where the log output will go.
|
void |
setMaxBackupIndex(int maxBackups)
Sets the maximum number of backup files to keep around.
|
void |
setMaxFileSize(String value)
Sets the maximum size that the output file is allowed to reach before being rolled over to backup files.
|
void |
setMaximumFileSize(long maxFileSize)
Sets the maximum size that the output file is allowed to reach before being rolled over to backup files.
|
protected void |
setQWForFiles(Writer writer)
Sets the quiet writer being used.
|
protected void |
subAppend(LoggingEvent event)
This method differentiates RollingFileAppender from its super class.
|
activateOptions, closeFile, getAppend, getBufferedIO, getBufferSize, getFile, reset, setAppend, setBufferedIO, setBufferSize, setFileappend, checkEntryConditions, close, closeWriter, createWriter, getEncoding, getImmediateFlush, requiresLayout, setEncoding, setErrorHandler, setImmediateFlush, setWriter, shouldFlush, writeFooter, writeHeaderaddFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThresholdprotected long maxFileSize
protected int maxBackupIndex
public RollingFileAppender()
parents constructor.public RollingFileAppender(Layout layout, String filename, boolean append) throws IOException
filename. The opened filename will
become the ouput destination for this appender.
If the append parameter is true, the file will be appended to. Otherwise, the file desginated by
filename will be truncated before being opened.
IOExceptionpublic RollingFileAppender(Layout layout, String filename) throws IOException
filename. The opened filename will become the
output destination for this appender.
The file will be appended to.
IOExceptionpublic int getMaxBackupIndex()
public long getMaximumFileSize()
public void rollOver()
If MaxBackupIndex is positive, then files {File.1, ...,
File.MaxBackupIndex -1} are renamed to {File.2, ..., File.MaxBackupIndex}.
Moreover, File is renamed File.1 and closed. A new File is created to receive
further log output.
If MaxBackupIndex is equal to zero, then the File is truncated with no backup files
created.
public void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException
FileAppenderIf there was already an opened file, then the previous file is closed first.
Do not use this method directly. To configure a FileAppender or one of its subclasses, set its properties one by one and then call activateOptions.
setFile in class FileAppenderfileName - The path to the log file.append - If true will append to fileName. Otherwise will truncate fileName.IOExceptionpublic void setMaxBackupIndex(int maxBackups)
The MaxBackupIndex option determines how many backup files are kept before the oldest is erased. This option
takes a positive integer value. If set to zero, then there will be no backup files and the log file will be truncated
when it reaches MaxFileSize.
public void setMaximumFileSize(long maxFileSize)
This method is equivalent to setMaxFileSize(java.lang.String) except that it is required for differentiating the setter taking
a long argument from the setter taking a String argument by the JavaBeans
Introspector.
setMaxFileSize(String)public void setMaxFileSize(String value)
In configuration files, the MaxFileSize option takes an long integer in the range 0 - 2^63. You can specify the value with the suffixes "KB", "MB" or "GB" so that the integer is interpreted being expressed respectively in kilobytes, megabytes or gigabytes. For example, the value "10KB" will be interpreted as 10240.
protected void setQWForFiles(Writer writer)
FileAppenderRollingFileAppender.setQWForFiles in class FileAppenderprotected void subAppend(LoggingEvent event)
subAppend in class WriterAppenderevent - The event to log.Copyright © 1999-2022 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.