Class FileAppender
- All Implemented Interfaces:
org.apache.log4j.Appender,org.apache.log4j.spi.OptionHandler
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.log4j.AppenderSkeleton
org.apache.log4j.AppenderSkeleton.NoOpErrorHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanDo we do bufferedIO?protected intDetermines the size of IO buffer be.protected booleanControls file truncatation.protected StringThe name of the log file.Fields inherited from class org.apache.log4j.WriterAppender
encoding, immediateFlush, qwFields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor does not do anything.FileAppender(org.apache.log4j.Layout layout, String fileName) Instantiate a FileAppender and open the file designated byfilename.FileAppender(org.apache.log4j.Layout layout, String fileName, boolean append) Instantiate a FileAppender and open the file designated byfileName.FileAppender(org.apache.log4j.Layout layout, String fileName, boolean append, boolean bufferedIO, int bufferSize) Instantiate aFileAppenderand open the file designated byfileName. -
Method Summary
Modifier and TypeMethodDescriptionvoidIf the value of File is notnull, thensetFile(java.lang.String)is called with the values of File and Append properties.protected voidCloses the previously opened file.booleanReturns the value of the Append option.booleanGet the value of the BufferedIO option.intGet the size of the IO buffer.getFile()Returns the value of the File option.protected voidreset()Close any previously opened file and call the parent'sreset.voidsetAppend(boolean flag) The Append option takes a boolean value.voidsetBufferedIO(boolean bufferedIO) The BufferedIO option takes a boolean value.voidsetBufferSize(int bufferSize) Set the size of the IO buffer.voidThe File property takes a string value which should be the name of the file to append to.voidSets and opens the file where the log output will go.protected voidsetQWForFiles(Writer writer) Sets the quiet writer being used.Methods inherited from class org.apache.log4j.WriterAppender
append, checkEntryConditions, close, closeWriter, createWriter, getEncoding, getImmediateFlush, requiresLayout, setEncoding, setErrorHandler, setImmediateFlush, setWriter, shouldFlush, subAppend, writeFooter, writeHeaderMethods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold
-
Field Details
-
fileAppend
Controls file truncatation. The default value for this variable istrue, meaning that by default aFileAppenderwill append to an existing file and not truncate it.This option is meaningful only if the FileAppender opens the file.
-
fileName
The name of the log file. -
bufferedIO
Do we do bufferedIO? -
bufferSize
Determines the size of IO buffer be. Default is 8K.
-
-
Constructor Details
-
FileAppender
public FileAppender()The default constructor does not do anything. -
FileAppender
public FileAppender(org.apache.log4j.Layout layout, String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException Instantiate aFileAppenderand open the file designated byfileName. The opened filename will become the output destination for this appender.If the
appendparameter is true, the file will be appended to. Otherwise, the file designated byfileNamewill be truncated before being opened.If the
bufferedIOparameter istrue, then buffered IO will be used to write to the output file.- Throws:
IOException
-
FileAppender
public FileAppender(org.apache.log4j.Layout layout, String fileName, boolean append) throws IOException Instantiate a FileAppender and open the file designated byfileName. The opened filename will become the output destination for this appender.If the
appendparameter is true, the file will be appended to. Otherwise, the file designated byfileNamewill be truncated before being opened.- Throws:
IOException
-
FileAppender
Instantiate 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:
IOException
-
-
Method Details
-
setFile
The File property takes a string value which should be the name of the file to append to.Note that the special values "System.out" or "System.err" are no longer honored.
Note: Actual opening of the file is made when
activateOptions()is called, not when the options are set. -
getAppend
Returns the value of the Append option. -
getFile
Returns the value of the File option. -
activateOptions
If the value of File is notnull, thensetFile(java.lang.String)is called with the values of File and Append properties.- Specified by:
activateOptionsin interfaceorg.apache.log4j.spi.OptionHandler- Overrides:
activateOptionsin classorg.apache.log4j.WriterAppender- Since:
- 0.8.1
-
closeFile
Closes the previously opened file. -
getBufferedIO
Get the value of the BufferedIO option.BufferedIO will significatnly increase performance on heavily loaded systems.
-
getBufferSize
Get the size of the IO buffer. -
setAppend
The Append option takes a boolean value. It is set totrueby default. If true, thenFilewill be opened in append mode bysetFile(see above). Otherwise,setFilewill openFilein truncate mode.Note: Actual opening of the file is made when
activateOptions()is called, not when the options are set. -
setBufferedIO
The BufferedIO option takes a boolean value. It is set tofalseby default. If true, thenFilewill be opened and the resultingWriterwrapped around aBufferedWriter. BufferedIO will significatnly increase performance on heavily loaded systems. -
setBufferSize
Set the size of the IO buffer. -
setFile
public void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException Sets 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.
- Parameters:
fileName- The path to the log file.append- If true will append to fileName. Otherwise will truncate fileName.- Throws:
IOException
-
setQWForFiles
Sets the quiet writer being used. This method is overriden byRollingFileAppender. -
reset
Close any previously opened file and call the parent'sreset.- Overrides:
resetin classorg.apache.log4j.WriterAppender
-