- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- ch.qos.logback.core.UnsynchronizedAppenderBase<E>
-
- ch.qos.logback.core.OutputStreamAppender<E>
-
- All Implemented Interfaces:
Appender<E>,ContextAware,FilterAttachable<E>,LifeCycle
- Direct Known Subclasses:
ConsoleAppender,FileAppender
public class OutputStreamAppender<E> extends UnsynchronizedAppenderBase<E>
OutputStreamAppender appends events to aOutputStream. 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#OutputStreamAppender- Author:
- Ceki Gülcü
-
-
Field Summary
Fields Modifier and Type Field Description protected Encoder<E>encoderIt is the encoder which is ultimately responsible for writing the event to anOutputStream.protected ReentrantLockstreamWriteLockAll synchronization in this class is done via the lock object.-
Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
name, started
-
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
-
Constructor Summary
Constructors Constructor Description OutputStreamAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappend(E eventObject)protected voidcloseOutputStream()Close the underlyingOutputStream.Encoder<E>getEncoder()OutputStreamgetOutputStream()The underlying output stream used by this appender.booleanisImmediateFlush()voidsetEncoder(Encoder<E> encoder)voidsetImmediateFlush(boolean immediateFlush)voidsetLayout(Layout<E> layout)voidsetOutputStream(OutputStream outputStream)Sets theOutputStreamwhere the log output will go.voidstart()Checks that requires parameters are set and if everything is in order, activates this appender.voidstop()Stop this appender instance.protected voidsubAppend(E event)Actual writing occurs here.protected voidupdateByteCount(byte[] byteArray)protected voidwriteByteArrayToOutputStreamWithPossibleFlush(byte[] byteArray)A simple method to write to an outputStream and flush the stream if immediateFlush is set to true.protected voidwriteOut(E event)-
Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
addFilter, buildReentryGuard, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, 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
-
-
-
-
Field Detail
-
encoder
protected Encoder<E> encoder
It is the encoder which is ultimately responsible for writing the event to anOutputStream.
-
streamWriteLock
protected final ReentrantLock streamWriteLock
All synchronization in this class is done via the lock object.
-
-
Constructor Detail
-
OutputStreamAppender
public OutputStreamAppender()
-
-
Method Detail
-
getOutputStream
public OutputStream getOutputStream()
The underlying output stream used by this appender.- Returns:
-
start
public void start()
Checks that requires parameters are set and if everything is in order, activates this appender.- Specified by:
startin interfaceLifeCycle- Overrides:
startin classUnsynchronizedAppenderBase<E>
-
append
protected void append(E eventObject)
- Specified by:
appendin classUnsynchronizedAppenderBase<E>
-
stop
public void stop()
Stop this appender instance. The underlying stream or writer is also closed.Stopped appenders cannot be reused.
- Specified by:
stopin interfaceLifeCycle- Overrides:
stopin classUnsynchronizedAppenderBase<E>
-
closeOutputStream
protected void closeOutputStream()
Close the underlyingOutputStream.
-
setOutputStream
public void setOutputStream(OutputStream outputStream)
Sets the
OutputStreamwhere the log output will go. The specifiedOutputStreammust be opened by the user and be writable. TheOutputStreamwill be closed when the appender instance is closed.- Parameters:
outputStream- An already opened OutputStream.
-
writeOut
protected void writeOut(E event) throws IOException
- Throws:
IOException
-
updateByteCount
protected void updateByteCount(byte[] byteArray)
-
writeByteArrayToOutputStreamWithPossibleFlush
protected final void writeByteArrayToOutputStreamWithPossibleFlush(byte[] byteArray) throws IOException
A simple method to write to an outputStream and flush the stream if immediateFlush is set to true.- Throws:
IOException- Since:
- 1.3.9/1.4.9
-
subAppend
protected void subAppend(E event)
Actual writing occurs here.Most subclasses of
WriterAppenderwill need to override this method.- Since:
- 0.9.0
-
getEncoder
public Encoder<E> getEncoder()
-
setEncoder
public void setEncoder(Encoder<E> encoder)
-
isImmediateFlush
public boolean isImmediateFlush()
-
setImmediateFlush
public void setImmediateFlush(boolean immediateFlush)
-
-