Class ChunkedLoggingStream

java.lang.Object
java.io.OutputStream
org.elasticsearch.common.logging.ChunkedLoggingStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ChunkedLoggingStream extends OutputStream
An OutputStream which Gzip-compresses the written data, Base64-encodes it, and writes it in fixed-size chunks to a logger. This is useful for debugging information that may be too large for a single log message and/or which may include data which cannot be recorded faithfully in plain-text (e.g. binary data or data with significant whitespace).
  • Method Details

    • create

      public static OutputStream create(org.apache.logging.log4j.Logger logger, org.apache.logging.log4j.Level level, String prefix, ReferenceDocs referenceDocs) throws IOException
      Create an OutputStream which Gzip-compresses the written data, Base64-encodes it, and writes it in fixed-size (2kiB) chunks to the given logger. If the data fits into a single chunk then the output looks like this:
       $PREFIX (gzip compressed and base64-encoded; for details see ...): H4sIAAAAA...
       
      If there are multiple chunks then they are written like this:
       $PREFIX [part 1]: H4sIAAAAA...
       $PREFIX [part 2]: r38c4MBHO...
       $PREFIX [part 3]: ECyRFONaL...
       $PREFIX [part 4]: kTgm+Qswm...
       $PREFIX (gzip compressed, base64-encoded, and split into 4 parts on preceding log lines; for details see ...)
       
      Parameters:
      logger - The logger to receive the chunks of data.
      level - The log level to use for the logging.
      prefix - A prefix for each chunk, which should be reasonably unique to allow for reconstruction of the original message even if multiple such streams are used concurrently.
      referenceDocs - A link to the relevant reference docs to help users interpret the output. Relevant reference docs are required because the output is rather human-unfriendly and we need somewhere to describe how to decode it.
      Throws:
      IOException
    • write

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException