ch.qos.logback.core
Class WriterAppender<E>

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.UnsynchronizedAppenderBase<E>
          extended by ch.qos.logback.core.WriterAppender<E>
All Implemented Interfaces:
Appender<E>, ContextAware, FilterAttachable<E>, LifeCycle
Direct Known Subclasses:
ConsoleAppender, FileAppender

public class WriterAppender<E>
extends UnsynchronizedAppenderBase<E>

WriterAppender appends events to a hava.io.Writer. This class provides basic services that other appenders build upon. For more information about this appender, please refer to the online manual at http://logback.qos.ch/manual/appenders.html#WriterAppender

Author:
Ceki Gülcü

Field Summary
 
Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
layout, name, started
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
WriterAppender()
          The default constructor does nothing.
 
Method Summary
protected  void append(E eventObject)
           
protected  void closeWriter()
          Close the underlying Writer.
protected  OutputStreamWriter createWriter(OutputStream os)
          Returns an OutputStreamWriter when passed an OutputStream.
 String getEncoding()
           
 boolean getImmediateFlush()
          Returns value of the ImmediateFlush option.
 void setEncoding(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(Writer writer)
           Sets the Writer where the log output will go.
 void start()
          Checks that requires parameters are set and if everything is in order, activates this appender.
 void stop()
          Stop this appender instance.
protected  void subAppend(E event)
          Actual writing occurs here.
protected  void writerWrite(String s, boolean flush)
           
 
Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getFirstFilter, getLayout, getName, isStarted, setLayout, setName, toString
 
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
 

Constructor Detail

WriterAppender

public WriterAppender()
The default constructor does nothing.

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.


start

public void start()
Checks that requires parameters are set and if everything is in order, activates this appender.

Specified by:
start in interface LifeCycle
Overrides:
start in class UnsynchronizedAppenderBase<E>

append

protected void append(E eventObject)
Specified by:
append in class UnsynchronizedAppenderBase<E>

stop

public void stop()
Stop this appender instance. The underlying stream or writer is also closed.

Stopped appenders cannot be reused.

Specified by:
stop in interface LifeCycle
Overrides:
stop in class UnsynchronizedAppenderBase<E>

closeWriter

protected void closeWriter()
Close the underlying Writer.


createWriter

protected OutputStreamWriter createWriter(OutputStream os)
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.


getEncoding

public String getEncoding()

setEncoding

public void setEncoding(String value)

setWriter

public void setWriter(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.

Parameters:
writer - An already opened Writer.

writerWrite

protected void writerWrite(String s,
                           boolean flush)
                    throws IOException
Throws:
IOException

subAppend

protected void subAppend(E event)
Actual writing occurs here.

Most subclasses of WriterAppender will need to override this method.

Since:
0.9.0


Copyright © 2005-2009 QOS.ch. All Rights Reserved.