Class LoggerUtils.LoggingOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable
    Enclosing class:
    LoggerUtils

    public static class LoggerUtils.LoggingOutputStream
    extends ByteArrayOutputStream
    An OutputStream that writes contents to a Logger upon each call to flush() Original URL: https://blogs.oracle.com/nickstephen/entry/java_redirecting_system_out_and Author gives permission for free use in blog comments section.
    • Constructor Detail

      • LoggingOutputStream

        public LoggingOutputStream​(Logger logger,
                                   Level level)
        Constructor
        Parameters:
        logger - Logger to write to
        level - Level at which to write the log message
    • Method Detail

      • flush

        public void flush()
                   throws IOException
        upon flush() write the existing contents of the OutputStream to the logger as a log record.
        Specified by:
        flush in interface Flushable
        Overrides:
        flush in class OutputStream
        Throws:
        IOException - in case of error