Class LoggingOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class LoggingOutputStream
    extends java.io.OutputStream
    OutputStream which can be used to redirect all stdout and stderr to a logger. Usage: System.setOut(new PrintStream(new LoggingOutputStream(LoggingOutputStream.LoggingLevel.INFO, log, "StdOut: "))); System.setErr(new PrintStream(new LoggingOutputStream(LoggingOutputStream.LoggingLevel.WARN, log, "StdErr: ")));
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LoggingOutputStream.LoggingLevel
      Enum representing the standard logging levels for commons logging.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        close, flush, nullOutputStream, write, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LoggingOutputStream

        public LoggingOutputStream​(LoggingOutputStream.LoggingLevel loggingLevel,
                                   org.slf4j.Logger logger,
                                   java.lang.String prefix)
        Constructor for the class.
        Parameters:
        loggingLevel - The logging level at which to log messages from this instance.
        logger - The logger to which messages will be logged.
        prefix - A prefix by which output from this instance can be identified.
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException