java.lang.Object | ||
↳ | org.apache.log4j.AppenderSkeleton | |
↳ | org.apache.log4j.WriterAppender |
Known Direct Subclasses |
Known Indirect Subclasses |
WriterAppender appends log events to a java.io.Writer or an java.io.OutputStream depending on the user's choice.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
encoding | The encoding to use when writing. | ||||||||||
immediateFlush | Immediate flush means that the underlying writer or output stream will be flushed at the end of each append operation unless shouldFlush() is overridden. | ||||||||||
qw | This is the quietWriter where we will write
to. |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.log4j.AppenderSkeleton
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This default constructor does nothing.
| |||||||||||
Instantiate a WriterAppender and set the output destination to a
new OutputStreamWriter initialized with
os
as its OutputStream. | |||||||||||
Instantiate a WriterAppender and set the output destination to
writer . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Does nothing.
| |||||||||||
This method is called by the
doAppend(LoggingEvent)
method. | |||||||||||
Close this appender instance.
| |||||||||||
Returns value of the ImmediateFlush option.
| |||||||||||
The WriterAppender requires a layout.
| |||||||||||
Set the
ErrorHandler for this WriterAppender and also the
underlying QuietWriter if any. | |||||||||||
If the ImmediateFlush option is set to
true , the appender will flush at the end of each
write. | |||||||||||
Sets the Writer where the log output will go. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method determines if there is a sense in attempting to append.
| |||||||||||
Close the underlying java.io.Writer.
| |||||||||||
Returns an OutputStreamWriter when passed an OutputStream.
| |||||||||||
Clear internal references to the writer and other variables.
| |||||||||||
Determines whether the writer should be flushed after
this event is written.
| |||||||||||
Actual writing occurs here.
| |||||||||||
Write a footer as produced by the embedded layout's
getFooter() method. | |||||||||||
Write a header as produced by the embedded layout's
getHeader() method. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.log4j.AppenderSkeleton
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.apache.log4j.Appender
| |||||||||||
From interface
org.apache.log4j.spi.OptionHandler
|
The encoding to use when writing.
The
encoding
variable is set to null by
default which results in the utilization of the system's default
encoding.
Immediate flush means that the underlying writer or output stream
will be flushed at the end of each append operation unless shouldFlush()
is overridden. Immediate
flush is slower but ensures that each append request is actually
written. If immediateFlush
is set to
false
, then there is a good chance that the last few
logs events are not actually written to persistent media if and
when the application crashes.
The immediateFlush
variable is set to
true
by default.
This default constructor does nothing.
Instantiate a WriterAppender and set the output destination to a
new OutputStreamWriter initialized with os
as its OutputStream.
Instantiate a WriterAppender and set the output destination to
writer
.
The writer
must have been previously opened by
the user.
Does nothing.
This method is called by the doAppend(LoggingEvent)
method.
If the output stream exists and is writable then write a log
statement to the output stream. Otherwise, write a single warning
message to System.err
.
The format of the output will depend on this appender's layout.
Close this appender instance. The underlying stream or writer is also closed.
Closed appenders cannot be reused.
Returns value of the ImmediateFlush option.
The WriterAppender requires a layout. Hence, this method returns
true
.
Set the ErrorHandler
for this WriterAppender and also the
underlying QuietWriter
if any.
If the ImmediateFlush option is set to
true
, the appender will flush at the end of each
write. This is the default behavior. If the option is set to
false
, then the underlying stream can defer writing
to physical medium to a later time.
Avoiding the flush operation at the end of each append results in a performance gain of 10 to 20 percent. However, there is safety tradeoff involved in skipping flushing. Indeed, when flushing is skipped, then it is likely that the last few log events will not be recorded on disk when the application exits. This is a high price to pay even for a 20% performance gain.
Sets the Writer where the log output will go. The specified Writer must be opened by the user and be writable.
The java.io.Writer
will be closed when the
appender instance is closed.
WARNING: Logging to an unopened Writer will fail.
writer | An already opened Writer. |
---|
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.
Close the underlying java.io.Writer.
Returns an OutputStreamWriter when passed an OutputStream. The
encoding used will depend on the value of the
encoding
property. If the encoding value is
specified incorrectly the writer will be opened using the default
system encoding (an error message will be printed to the loglog.
Clear internal references to the writer and other variables. Subclasses can override this method for an alternate closing behavior.
Determines whether the writer should be flushed after this event is written.
Actual writing occurs here.
Most subclasses of WriterAppender
will need to
override this method.
Write a footer as produced by the embedded layout's getFooter()
method.
Write a header as produced by the embedded layout's getHeader()
method.