org.jboss.logging.jdk.handlers
Class WriterHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by org.jboss.logging.jdk.handlers.HandlerSkeleton
          extended by org.jboss.logging.jdk.handlers.WriterHandler
Direct Known Subclasses:
FileHandler

public class WriterHandler
extends HandlerSkeleton

A base handler that outputs log messages to a Writer

Version:
$Revision: 1.2 $
Author:
Scott.Stark@jboss.org

Field Summary
protected  boolean bufferedIO
          Do we do bufferedIO?
protected  int bufferSize
          Determines the size of IO buffer be.
protected  boolean immediateFlush
          Immediate flush means that the underlying writer or output stream will be flushed at the end of each append operation.
 
Fields inherited from class org.jboss.logging.jdk.handlers.HandlerSkeleton
name
 
Constructor Summary
WriterHandler()
           
WriterHandler(OutputStream output, Formatter formatter)
           
 
Method Summary
protected  boolean checkEntryConditions(LogRecord record)
           
 void close()
           
 void flush()
           
 int getBufferSize()
           
 boolean getImmediateFlush()
          Returns value of the ImmediateFlush option.
 boolean isBufferedIO()
           
 void publish(LogRecord record)
           
 void setBufferedIO(boolean bufferedIO)
          The BufferedIO option takes a boolean value.
 void setBufferSize(int bufferSize)
          Set the size of the IO buffer.
 void setEncoding(String encoding)
           
 void setImmediateFlush(boolean value)
          If the ImmediateFlush option is set to true, the appender will flush at the end of each write.
protected  void setOutputStream(OutputStream out)
          Change the output stream.
protected  void subPublish(LogRecord record)
          Actual writing occurs here.
 
Methods inherited from class org.jboss.logging.jdk.handlers.HandlerSkeleton
activateOptions, debug, getName, setName
 
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setErrorManager, setFilter, setFormatter, setLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

immediateFlush

protected boolean immediateFlush
Immediate flush means that the underlying writer or output stream will be flushed at the end of each append operation. 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.


bufferedIO

protected boolean bufferedIO
Do we do bufferedIO?


bufferSize

protected int bufferSize
Determines the size of IO buffer be. Default is 8K.

Constructor Detail

WriterHandler

public WriterHandler()

WriterHandler

public WriterHandler(OutputStream output,
                     Formatter formatter)
Method Detail

setImmediateFlush

public void setImmediateFlush(boolean value)
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.


getImmediateFlush

public boolean getImmediateFlush()
Returns value of the ImmediateFlush option.


isBufferedIO

public boolean isBufferedIO()

setBufferedIO

public void setBufferedIO(boolean bufferedIO)
The BufferedIO option takes a boolean value. It is set to 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.


getBufferSize

public int getBufferSize()

setBufferSize

public void setBufferSize(int bufferSize)
Set the size of the IO buffer.


setEncoding

public void setEncoding(String encoding)
                 throws SecurityException,
                        UnsupportedEncodingException
Overrides:
setEncoding in class Handler
Throws:
SecurityException
UnsupportedEncodingException

flush

public void flush()
Specified by:
flush in class Handler

close

public void close()
Specified by:
close in class Handler

publish

public void publish(LogRecord record)
Specified by:
publish in class Handler

checkEntryConditions

protected boolean checkEntryConditions(LogRecord record)

subPublish

protected void subPublish(LogRecord record)
Actual writing occurs here. Most subclasses of WriterHandler will need to override this method.


setOutputStream

protected void setOutputStream(OutputStream out)
Change the output stream.

If there is a current output stream then the Formatter's tail string is written and the stream is flushed and closed. Then the output stream is replaced with the new output stream.

Parameters:
out - New output stream. May not be null.
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.