Class LoggingOutputStream

java.lang.Object
java.io.OutputStream
org.terracotta.utilities.logging.LoggingOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class LoggingOutputStream extends OutputStream
Implements an OutputStream that forwards lines written to it to a Logger at a specified level. Bytes are accumulated by this OutputStream until a System.lineSeparator() value is found; once the line ending is found, the line is flushed to the logger.

Bytes written to a LoggingOutputStream instance must have been encoded using UTF-8. This affects proper recognition of line separators and re-assembly of logged strings.

  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • DEFAULT_BUFFER_SIZE

      public static final int DEFAULT_BUFFER_SIZE
      See Also:
    • LOG_METHODS

      private static final Map<org.slf4j.event.Level,MethodHandle> LOG_METHODS
    • handle

      private final MethodHandle handle
    • twoByteLineSeparator

      private final boolean twoByteLineSeparator
    • eol

      private final byte eol
    • eolLeader

      private final byte eolLeader
    • closed

      private volatile boolean closed
    • buffer

      private byte[] buffer
    • bufferSize

      private int bufferSize
    • byteCount

      private int byteCount
    • haveLeader

      private boolean haveLeader
  • Constructor Details

    • LoggingOutputStream

      public LoggingOutputStream(org.slf4j.Logger logger, org.slf4j.event.Level level)
      Creates a new LoggingOutputStream writing to the provided logger and the specified level.

      Bytes written to this LoggingOutputStream must be UTF-8 encoded characters.

      Parameters:
      logger - the SLF4J Logger instance to which the stream should write
      level - the SLF4J level at which the stream is recorded to logger
  • Method Details