public class FileAppender extends WriterAppender
Support for java.io.Writer
and console appending has been deprecated and then removed. See the
replacement solutions: WriterAppender
and ConsoleAppender
.
AppenderSkeleton.NoOpErrorHandler
Modifier and Type | Field and Description |
---|---|
protected boolean |
bufferedIO
Do we do bufferedIO?
|
protected int |
bufferSize
Determines the size of IO buffer be.
|
protected boolean |
fileAppend
Controls file truncatation.
|
protected String |
fileName
The name of the log file.
|
encoding, immediateFlush, qw
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
Constructor and Description |
---|
FileAppender()
The default constructor does not do anything.
|
FileAppender(Layout layout,
String filename)
Constructs a FileAppender and open the file designated by
filename . |
FileAppender(Layout layout,
String filename,
boolean append)
Constructs a FileAppender and open the file designated by
filename . |
FileAppender(Layout layout,
String filename,
boolean append,
boolean bufferedIO,
int bufferSize)
Constructs a
FileAppender and open the file designated by filename . |
Modifier and Type | Method and Description |
---|---|
void |
activateOptions()
If the value of File is not
null , then setFile(java.lang.String) is called with the values of File
and Append properties. |
protected void |
closeFile()
Closes the previously opened file.
|
boolean |
getAppend()
Returns the value of the Append option.
|
boolean |
getBufferedIO()
Get the value of the BufferedIO option.
|
int |
getBufferSize()
Get the size of the IO buffer.
|
String |
getFile()
Returns the value of the File option.
|
protected void |
reset()
Close any previously opened file and call the parent's
reset . |
void |
setAppend(boolean flag)
The Append option takes a boolean value.
|
void |
setBufferedIO(boolean bufferedIO)
The BufferedIO option takes a boolean value.
|
void |
setBufferSize(int bufferSize)
Set the size of the IO buffer.
|
void |
setFile(String file)
The File property takes a string value which should be the name of the file to append to.
|
void |
setFile(String fileName,
boolean append,
boolean bufferedIO,
int bufferSize)
Sets and opens the file where the log output will go.
|
protected void |
setQWForFiles(Writer writer)
Sets the quiet writer being used.
|
append, checkEntryConditions, close, closeWriter, createWriter, getEncoding, getImmediateFlush, requiresLayout, setEncoding, setErrorHandler, setImmediateFlush, setWriter, shouldFlush, subAppend, writeFooter, writeHeader
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold
protected boolean fileAppend
true
, meaning that by default a
FileAppender
will append to an existing file and not truncate it.
This option is meaningful only if the FileAppender opens the file.
protected String fileName
protected boolean bufferedIO
protected int bufferSize
public FileAppender()
public FileAppender(Layout layout, String filename) throws IOException
filename
. The opened filename will become the
output destination for this appender.
The file will be appended to.
IOException
public FileAppender(Layout layout, String filename, boolean append) throws IOException
filename
. The opened filename will become the
output destination for this appender.
If the append
parameter is true, the file will be appended to. Otherwise, the file designated by
filename
will be truncated before being opened.
IOException
public FileAppender(Layout layout, String filename, boolean append, boolean bufferedIO, int bufferSize) throws IOException
FileAppender
and open the file designated by filename
. The opened filename
will become the output destination for this appender.
If the append
parameter is true, the file will be appended to. Otherwise, the file designated by
filename
will be truncated before being opened.
If the bufferedIO
parameter is true
, then buffered IO will be used to write to the output
file.
IOException
public void activateOptions()
null
, then setFile(java.lang.String)
is called with the values of File
and Append properties.activateOptions
in interface OptionHandler
activateOptions
in class WriterAppender
protected void closeFile()
public boolean getAppend()
public boolean getBufferedIO()
BufferedIO will significatnly increase performance on heavily loaded systems.
public int getBufferSize()
public String getFile()
protected void reset()
reset
.reset
in class WriterAppender
public void setAppend(boolean flag)
true
by default. If true, then
File
will be opened in append mode by setFile
(see above). Otherwise, setFile
will open File
in truncate mode.
Note: Actual opening of the file is made when activateOptions()
is called, not when the options are set.
public void setBufferedIO(boolean bufferedIO)
false
by default. If true, then
File
will be opened and the resulting Writer
wrapped around a BufferedWriter
.
BufferedIO will significatnly increase performance on heavily loaded systems.public void setBufferSize(int bufferSize)
public void setFile(String file)
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.
public void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException
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.
fileName
- The path to the log file.append
- If true will append to fileName. Otherwise will truncate fileName.IOException
protected void setQWForFiles(Writer writer)
RollingFileAppender
.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.