|
Log4j 1.3alpha-5 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.log4j.spi.ComponentBase | +--org.apache.log4j.AppenderSkeleton | +--org.apache.log4j.WriterAppender
WriterAppender appends log events to a Writer
or an
OutputStream
depending on the user's choice.
Field Summary | |
protected java.lang.String |
encoding
The encoding to use when opening an InputStream. |
protected boolean |
immediateFlush
Immediate flush means that the underlying writer or output stream will be flushed at the end of each append operation. |
protected boolean |
inOrder
Set to true when the appender is in functioning order. |
protected java.io.Writer |
writer
This is the Writer where we will write to. |
Fields inherited from class org.apache.log4j.AppenderSkeleton |
closed, headFilter, layout, name, tailFilter, threshold |
Fields inherited from class org.apache.log4j.spi.ComponentBase |
repository |
Constructor Summary | |
WriterAppender()
This default constructor does nothing. |
|
WriterAppender(Layout layout,
java.io.OutputStream os)
Deprecated. This constructor will be removed with no replacement in future log4j versions. |
|
WriterAppender(Layout layout,
java.io.Writer writer)
Deprecated. This constructor will be removed with no replacement in future log4j versions |
Method Summary | |
void |
activateOptions()
Does nothing. |
void |
append(LoggingEvent event)
This method is called by the AppenderSkeleton.doAppend(org.apache.log4j.spi.LoggingEvent)
method.
|
protected boolean |
checkEntryConditions()
This method determines if there is a sense in attempting to append. |
void |
close()
Close this appender instance. |
protected void |
closeWriter()
Close the underlying Writer . |
protected java.io.OutputStreamWriter |
createWriter(java.io.OutputStream os)
Returns an OutputStreamWriter when passed an OutputStream. |
java.lang.String |
getEncoding()
|
boolean |
getImmediateFlush()
Returns value of the ImmediateFlush option. |
boolean |
requiresLayout()
The WriterAppender requires a layout. |
void |
setEncoding(java.lang.String value)
|
void |
setImmediateFlush(boolean value)
If the ImmediateFlush option is set to true , the appender will flush at the end of each
write. |
void |
setWriter(java.io.Writer writer)
Sets the Writer where the log output will go. |
protected void |
subAppend(LoggingEvent event)
Actual writing occurs here. |
protected void |
writeFooter()
Write a footer as produced by the embedded layout's Layout.getFooter() method. |
protected void |
writeHeader()
Write a header as produced by the embedded layout's Layout.getHeader() method. |
protected void |
xreset()
Deprecated. Use closeWriter() method instead. |
Methods inherited from class org.apache.log4j.AppenderSkeleton |
addFilter, clearFilters, doAppend, finalize, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold |
Methods inherited from class org.apache.log4j.spi.ComponentBase |
getLogger, setLoggerRepository |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.log4j.Appender |
setLoggerRepository |
Field Detail |
protected boolean inOrder
protected boolean immediateFlush
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.
protected java.lang.String encoding
The
encoding
variable is set to null by
default which results in the utilization of the system's default
encoding.
protected java.io.Writer writer
Writer
where we will write to.
Constructor Detail |
public WriterAppender()
public WriterAppender(Layout layout, java.io.OutputStream os)
OutputStreamWriter
initialized with os
as its
OutputStream
.
public WriterAppender(Layout layout, java.io.Writer writer)
writer
.
The writer
must have been previously opened by the user.
Method Detail |
public void setImmediateFlush(boolean value)
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.
public boolean getImmediateFlush()
public void activateOptions()
activateOptions
in interface OptionHandler
activateOptions
in class AppenderSkeleton
public void append(LoggingEvent event)
AppenderSkeleton.doAppend(org.apache.log4j.spi.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.
append
in class AppenderSkeleton
protected boolean checkEntryConditions()
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.
public void close()
Closed appenders cannot be reused.
setWriter(java.io.Writer)
protected void closeWriter()
Writer
.
protected java.io.OutputStreamWriter createWriter(java.io.OutputStream os)
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.
public java.lang.String getEncoding()
public void setEncoding(java.lang.String value)
public void setWriter(java.io.Writer writer)
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.protected void subAppend(LoggingEvent event)
Most subclasses of WriterAppender
will need to override
this method.
public boolean requiresLayout()
true
.
protected void xreset()
closeWriter()
method instead.
protected void writeFooter()
Layout.getFooter()
method.
protected void writeHeader()
Layout.getHeader()
method.
|
Log4j 1.3alpha-5 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |