Class RollingFileAppender
- java.lang.Object
-
- org.apache.log4j.AppenderSkeleton
-
- org.apache.log4j.WriterAppender
-
- org.apache.log4j.FileAppender
-
- org.apache.log4j.RollingFileAppender
-
- All Implemented Interfaces:
Appender,OptionHandler
public class RollingFileAppender extends FileAppender
RollingFileAppender extends FileAppender to backup the log files when they reach a certain size. The log4j extras companion includes alternatives which should be considered for new deployments and which are discussed in the documentation for org.apache.log4j.rolling.RollingFileAppender.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.log4j.AppenderSkeleton
AppenderSkeleton.NoOpErrorHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected intmaxBackupIndexThere is one backup file by default.protected longmaxFileSizeThe default maximum file size is 10MB.private longnextRollover-
Fields inherited from class org.apache.log4j.FileAppender
bufferedIO, bufferSize, fileAppend, fileName
-
Fields inherited from class org.apache.log4j.WriterAppender
encoding, immediateFlush, qw
-
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
-
-
Constructor Summary
Constructors Constructor Description RollingFileAppender()The default constructor simply calls itsparents constructor.RollingFileAppender(Layout layout, java.lang.String filename)Constructs a FileAppender and open the file designated byfilename.RollingFileAppender(Layout layout, java.lang.String filename, boolean append)Constructs a RollingFileAppender and open the file designated byfilename.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaxBackupIndex()Gets the value of the MaxBackupIndex option.longgetMaximumFileSize()Gets the maximum size that the output file is allowed to reach before being rolled over to backup files.voidrollOver()Implements the usual roll over behaviour.voidsetFile(java.lang.String fileName, boolean append, boolean bufferedIO, int bufferSize)Sets and opens the file where the log output will go.voidsetMaxBackupIndex(int maxBackups)Sets the maximum number of backup files to keep around.voidsetMaxFileSize(java.lang.String value)Sets the maximum size that the output file is allowed to reach before being rolled over to backup files.voidsetMaximumFileSize(long maxFileSize)Sets the maximum size that the output file is allowed to reach before being rolled over to backup files.protected voidsetQWForFiles(java.io.Writer writer)Sets the quiet writer being used.protected voidsubAppend(LoggingEvent event)This method differentiates RollingFileAppender from its super class.-
Methods inherited from class org.apache.log4j.FileAppender
activateOptions, closeFile, getAppend, getBufferedIO, getBufferSize, getFile, reset, setAppend, setBufferedIO, setBufferSize, setFile
-
Methods inherited from class org.apache.log4j.WriterAppender
append, checkEntryConditions, close, closeWriter, createWriter, getEncoding, getImmediateFlush, requiresLayout, setEncoding, setErrorHandler, setImmediateFlush, setWriter, shouldFlush, writeFooter, writeHeader
-
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold
-
-
-
-
Constructor Detail
-
RollingFileAppender
public RollingFileAppender()
The default constructor simply calls itsparents constructor.
-
RollingFileAppender
public RollingFileAppender(Layout layout, java.lang.String filename, boolean append) throws java.io.IOException
Constructs a RollingFileAppender and open the file designated byfilename. The opened filename will become the ouput destination for this appender.If the
appendparameter is true, the file will be appended to. Otherwise, the file desginated byfilenamewill be truncated before being opened.- Throws:
java.io.IOException
-
RollingFileAppender
public RollingFileAppender(Layout layout, java.lang.String filename) throws java.io.IOException
Constructs a FileAppender and open the file designated byfilename. The opened filename will become the output destination for this appender.The file will be appended to.
- Throws:
java.io.IOException
-
-
Method Detail
-
getMaxBackupIndex
public int getMaxBackupIndex()
Gets the value of the MaxBackupIndex option.
-
getMaximumFileSize
public long getMaximumFileSize()
Gets the maximum size that the output file is allowed to reach before being rolled over to backup files.- Since:
- 1.1
-
rollOver
public void rollOver()
Implements the usual roll over behaviour.If
MaxBackupIndexis positive, then files {File.1, ...,File.MaxBackupIndex -1} are renamed to {File.2, ...,File.MaxBackupIndex}. Moreover,Fileis renamedFile.1and closed. A newFileis created to receive further log output.If
MaxBackupIndexis equal to zero, then theFileis truncated with no backup files created.
-
setFile
public void setFile(java.lang.String fileName, boolean append, boolean bufferedIO, int bufferSize) throws java.io.IOExceptionDescription copied from class:FileAppenderSets and opens the file where the log output will go. The specified file must be writable.If 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.
- Overrides:
setFilein classFileAppender- Parameters:
fileName- The path to the log file.append- If true will append to fileName. Otherwise will truncate fileName.- Throws:
java.io.IOException
-
setMaxBackupIndex
public void setMaxBackupIndex(int maxBackups)
Sets the maximum number of backup files to keep around.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.
-
setMaximumFileSize
public void setMaximumFileSize(long maxFileSize)
Sets the maximum size that the output file is allowed to reach before being rolled over to backup files.This method is equivalent to
setMaxFileSize(java.lang.String)except that it is required for differentiating the setter taking alongargument from the setter taking aStringargument by the JavaBeansIntrospector.- See Also:
setMaxFileSize(String)
-
setMaxFileSize
public void setMaxFileSize(java.lang.String value)
Sets the maximum size that the output file is allowed to reach before being rolled over to backup files.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.
-
setQWForFiles
protected void setQWForFiles(java.io.Writer writer)
Description copied from class:FileAppenderSets the quiet writer being used. This method is overriden byRollingFileAppender.- Overrides:
setQWForFilesin classFileAppender
-
subAppend
protected void subAppend(LoggingEvent event)
This method differentiates RollingFileAppender from its super class.- Overrides:
subAppendin classWriterAppender- Parameters:
event- The event to log.- Since:
- 0.9.0
-
-