org.log4j.varia
Class ResilientFileAppender
java.lang.Object
|
+--org.log4j.AppenderSkeleton
|
+--org.log4j.FileAppender
|
+--org.log4j.varia.ResilientFileAppender
- All Implemented Interfaces:
- Appender, OptionHandler
- public class ResilientFileAppender
- extends FileAppender
This appender is resilient against moving of the log output
file. Before every write operation, it checks whether the target
log file has been moved by an external process. If that is the
case, a new output file is created.
This method of detecting externally triggered roll overs has the
following disadvantages:
- It adds the overhead of calling File.exists method before each
write.
- It is not guaranteed to work on all environments. For example,
on Windows NT, it is not possible to move an already open file.
- Since there is no proper synchronization between the external
process and the JVM doing the logging, race conditions are possible
and can result in the loss of log records.
For all these reasons, it is recommended that you use the ExternallyRolledFileAppender
.
- Since:
- version 0.9.0
- Author:
- Ceki Gülcü
Method Summary |
protected boolean |
checkEntryConditions()
This method determines if there is a sense in attempting to append. |
protected void |
reset()
|
void |
setFile(String fileName,
boolean append)
Sets and opens the file where the log output will
go. |
Methods inherited from class org.log4j.FileAppender |
activateOptions, append, close, closeWriterIfOurs, getOptionStrings, requiresLayout, setErrorHandler, setFile, setOption, setQWForFiles, setWriter, subAppend |
Methods inherited from class org.log4j.AppenderSkeleton |
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFirstFilter, getName, isAsSevereAsThreshold, setLayout, setName, setThreshold |
ResilientFileAppender
public ResilientFileAppender()
- Thia default constructor does nothing but call its super-class
constructor.
ResilientFileAppender
public ResilientFileAppender(Layout layout,
Writer writer)
- This constructor does nothing but call its super-class constructor
with the same parameters.
checkEntryConditions
protected boolean checkEntryConditions()
- Description copied from class:
FileAppender
- This method determines if there is a sense in attempting to append.
It checks whether there is a set output target and also if
there is a set layout. If these checks fail, then the boolean
value false
is returned.
- Overrides:
checkEntryConditions
in class FileAppender
setFile
public void setFile(String fileName,
boolean append)
throws IOException
- Description copied from class:
FileAppender
Sets and opens the file where the log output will
go. The specified file must be writable.
If there was already an opened stream opened through this
method, then the previous stream is closed first. If the stream
was opened by the user and passed to setWriter
, then the previous stream remains
untouched. It is the users responsability to close it.
- Overrides:
setFile
in class FileAppender
- Following copied from class:
org.log4j.FileAppender
- Parameters:
fileName
- The path to the log file.boolean
- If true will append to fileName. Otherwise will
truncate fileName.
reset
protected void reset()
- Overrides:
reset
in class FileAppender
Please notify me about new log4j releases.