|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.logging.Handler
org.x4juli.global.components.AbstractHandler
org.x4juli.handlers.WriterHandler
WriterHandler appends log events to a Writer.
| Attribute | Description | Required |
|---|---|---|
| .autoflush | Flush the writer after every record publishing or not. Should correspond to buffered IO. Allowed values "true" or "false". | No. Default is true. |
| .encoding | Specifies the encoding of the logfile. Allowed are all supported encodings of the platform. Supported Encodings | No. Default is value of system property "file.encoding". |
| .writer | Writer to publish logrecords to. Value is the full qualified classname of the writer. Do not specifiy any writer if you are using a subclass (FileHandler, RollingFileHandler). | YES. Default is null, which will lead to
errors. |
WriterHandler can be configured programattically or using
configuration by file. Do not use the default constructor in programattically use.
Logging API as a whole was originally done for Apache log4j. Juli is a port of main parts of that to complete the Java Logging APIs. All credits for initial idea, design, implementation, documentation belong to the log4j crew. This file was originally published by Ceki Gülcü. Please use exclusively the appropriate mailing lists for questions, remarks and contribution.
| Field Summary | |
protected boolean |
immediateFlush
Immediate flush means that the underlying writer or output stream will be flushed at the end of each append operation. |
protected java.io.Writer |
writer
This is the Writer where we will write to. |
| Fields inherited from class org.x4juli.global.components.AbstractHandler |
active, closed, extFormatter, headFilter, manager, name, repository, tailFilter |
| Fields inherited from class java.util.logging.Handler |
|
| Constructor Summary | |
WriterHandler()
Default Constructor instantiation used for configuration by file. |
|
WriterHandler(java.lang.String handlerName)
Utility Constructor - sets the formatter to null. |
|
| Method Summary | |
void |
activateOptions()
Activate the options that were previously set with calls to option setters.
This allows to defer activiation of the options until all options have
been set. This is required for components which have related options that
remain ambigous until all are set.
|
protected void |
appendLogRecord(ExtendedLogRecord record)
Subclasses of AbstractHandler should implement this method
to perform actual logging. See also AbstractHandler.publish(ExtendedLogRecord)
method. |
protected boolean |
checkEntryConditions()
This method determines if there is a sense in attempting to append. |
void |
close()
|
protected void |
closeWriter()
Close the underlying Writer. |
void |
configure()
Configure all properties of the object. Subclasses should call super.configure() to ensure proper configuration. |
protected java.io.OutputStreamWriter |
createWriter(java.io.OutputStream os)
Returns an OutputStreamWriter when passed an OutputStream. |
void |
flush()
|
java.lang.String |
getFullQualifiedClassName()
Determine performant the FullQualifiedClassName. Subclasses should overwrite this method. Dynamic determination is not recommended. |
boolean |
getImmediateFlush()
Returns value of the ImmediateFlush option. |
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(ExtendedLogRecord record)
Actual writing occurs here. |
protected void |
writeFooter()
Write a footer as produced by the embedded formatter's Formatter.getTail(java.util.logging.Handler) method. |
protected void |
writeHeader()
Write a header as produced by the embedded formatter's Formatter.getHead(java.util.logging.Handler) method. |
| Methods inherited from class org.x4juli.global.components.AbstractHandler |
addFilter, clearFilters, finalize, getFilter, getFormatter, getLogger, getLoggerRepository, getMessageProperties, getName, getNonFloodingLogger, getProperty, getProperty, getProperty, isActive, isClosed, isLoggable, isLoggable, publish, publish, resetErrorCount, setFilter, setFormatter, setName, setObjectStore, toString |
| Methods inherited from class java.util.logging.Handler |
getEncoding, getErrorManager, getLevel, reportError, setEncoding, setErrorManager, setLevel |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.x4juli.global.spi.ExtendedHandler |
getEncoding, getErrorManager, getLevel, setEncoding, setErrorManager, setLevel |
| Field Detail |
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.io.Writer writer
Writer where we will write to.
| Constructor Detail |
public WriterHandler()
Calls @link{AbstractHandler#AbstractHandler()}.
public WriterHandler(java.lang.String handlerName)
handlerName - of the current instance.| Method Detail |
public void close()
throws java.lang.SecurityException
java.lang.SecurityExceptionprotected void closeWriter()
Writer.
public void flush()
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 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 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()
This allows to defer activiation of the options until all options have
been set. This is required for components which have related options that
remain ambigous until all are set.
Subclasses have not set active to true, but call super as
last statement!
activateOptions in interface OptionHandleractivateOptions in class AbstractHandlerpublic void configure()
configure in class AbstractHandlerpublic java.lang.String getFullQualifiedClassName()
getFullQualifiedClassName in interface ExtendedHandlergetFullQualifiedClassName in class AbstractHandlerprotected void appendLogRecord(ExtendedLogRecord record)
AbstractHandler should implement this method
to perform actual logging. See also AbstractHandler.publish(ExtendedLogRecord)
method.
appendLogRecord in class AbstractHandlerrecord - to write to the logprotected void subAppend(ExtendedLogRecord record)
Most subclasses of WriterAppender will need to override
this method.
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.
protected void writeFooter()
Formatter.getTail(java.util.logging.Handler) method.
protected void writeHeader()
Formatter.getHead(java.util.logging.Handler) method.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||