Class OutputStreamAppender<E>

All Implemented Interfaces:
Appender<E>, ContextAware, FilterAttachable<E>, LifeCycle
Direct Known Subclasses:
ConsoleAppender, FileAppender

OutputStreamAppender appends events to a OutputStream. 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 Details

  • Constructor Details

  • Method Details

    • 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:
      start in interface LifeCycle
      Overrides:
      start in class UnsynchronizedAppenderBase<E>
    • setLayout

      public void setLayout(Layout<E> layout)
    • 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.

      The encoder is stopped as well, after the footer has been written and the stream closed, so that any resources it holds (for instance per-thread buffers) are released. Otherwise, each context reset or reconfiguration would leave the previous encoder and its resources behind.

      Stopped appenders cannot be reused.

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

      protected void closeOutputStream()
      Close the underlying OutputStream.
    • setOutputStream

      public void setOutputStream(OutputStream outputStream)

      Sets the OutputStream where the log output will go. The specified OutputStream must be opened by the user and be writable. The OutputStream will 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 WriterAppender will 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)