Class FileAppender
- java.lang.Object
-
- org.apache.log4j.AppenderSkeleton
-
- org.apache.log4j.WriterAppender
-
- org.apache.log4j.FileAppender
-
- All Implemented Interfaces:
Appender,OptionHandler
- Direct Known Subclasses:
RollingFileAppender
public class FileAppender extends WriterAppender
FileAppender appends log events to a file.Support for
java.io.Writerand console appending has been deprecated and then removed. See the replacement solutions:WriterAppenderandConsoleAppender.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.log4j.AppenderSkeleton
AppenderSkeleton.NoOpErrorHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanbufferedIODo we do bufferedIO?protected intbufferSizeDetermines the size of IO buffer be.protected booleanfileAppendControls file truncatation.protected java.lang.StringfileNameThe name of the log file.-
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 FileAppender()The default constructor does not do anything.FileAppender(Layout layout, java.lang.String filename)Constructs a FileAppender and open the file designated byfilename.FileAppender(Layout layout, java.lang.String filename, boolean append)Constructs a FileAppender and open the file designated byfilename.FileAppender(Layout layout, java.lang.String filename, boolean append, boolean bufferedIO, int bufferSize)Constructs aFileAppenderand open the file designated byfilename.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateOptions()If the value of File is notnull, thensetFile(java.lang.String)is called with the values of File and Append properties.protected voidcloseFile()Closes the previously opened file.booleangetAppend()Returns the value of the Append option.booleangetBufferedIO()Get the value of the BufferedIO option.intgetBufferSize()Get the size of the IO buffer.java.lang.StringgetFile()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.voidsetFile(java.lang.String file)The File property takes a string value which should be the name of the file to append to.voidsetFile(java.lang.String fileName, boolean append, boolean bufferedIO, int bufferSize)Sets and opens the file where the log output will go.protected voidsetQWForFiles(java.io.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, writeHeader
-
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold
-
-
-
-
Field Detail
-
fileAppend
protected boolean 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
protected java.lang.String fileName
The name of the log file.
-
bufferedIO
protected boolean bufferedIO
Do we do bufferedIO?
-
bufferSize
protected int bufferSize
Determines the size of IO buffer be. Default is 8K.
-
-
Constructor Detail
-
FileAppender
public FileAppender()
The default constructor does not do anything.
-
FileAppender
public FileAppender(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
-
FileAppender
public FileAppender(Layout layout, java.lang.String filename, boolean append) throws java.io.IOException
Constructs 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:
java.io.IOException
-
FileAppender
public FileAppender(Layout layout, java.lang.String filename, boolean append, boolean bufferedIO, int bufferSize) throws java.io.IOException
Constructs 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:
java.io.IOException
-
-
Method Detail
-
activateOptions
public void 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 interfaceOptionHandler- Overrides:
activateOptionsin classWriterAppender- Since:
- 0.8.1
-
closeFile
protected void closeFile()
Closes the previously opened file.
-
getAppend
public boolean getAppend()
Returns the value of the Append option.
-
getBufferedIO
public boolean getBufferedIO()
Get the value of the BufferedIO option.BufferedIO will significatnly increase performance on heavily loaded systems.
-
getBufferSize
public int getBufferSize()
Get the size of the IO buffer.
-
getFile
public java.lang.String getFile()
Returns the value of the File option.
-
reset
protected void reset()
Close any previously opened file and call the parent'sreset.- Overrides:
resetin classWriterAppender
-
setAppend
public void setAppend(boolean flag)
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
public void setBufferedIO(boolean bufferedIO)
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
public void setBufferSize(int bufferSize)
Set the size of the IO buffer.
-
setFile
public void setFile(java.lang.String file)
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.
-
setFile
public void setFile(java.lang.String fileName, boolean append, boolean bufferedIO, int bufferSize) throws java.io.IOExceptionSets 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:
java.io.IOException
-
setQWForFiles
protected void setQWForFiles(java.io.Writer writer)
Sets the quiet writer being used. This method is overriden byRollingFileAppender.
-
-