Class LoggerOutputStream

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

    public class LoggerOutputStream
    extends java.io.OutputStream
    Redirect an output stream to a logger. This class is useful to redirect standard output or standard error to a Logger. An example use is
     final LoggerOutputStream outputStream =
         new LoggerOutputStream( logger, Priority.DEBUG );
     final PrintStream output = new PrintStream( outputStream, true );
    
     System.setOut( output );
     
    Author:
    Avalon Development Team, Peter Donald
    • Constructor Summary

      Constructors 
      Constructor Description
      LoggerOutputStream​(Logger logger, Priority priority)
      Construct OutputStreamLogger to write to a particular logger at a particular priority.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void checkValid()
      Make sure stream is valid.
      void close()
      Shutdown stream.
      void flush()
      Flush data to underlying logger.
      void write​(int data)
      Write a single byte of data to output stream.
      • Methods inherited from class java.io.OutputStream

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

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

      • m_logger

        private final Logger m_logger
      • m_priority

        private final Priority m_priority
      • m_output

        private final java.lang.StringBuffer m_output
      • m_closed

        private boolean m_closed
    • Constructor Detail

      • LoggerOutputStream

        public LoggerOutputStream​(Logger logger,
                                  Priority priority)
        Construct OutputStreamLogger to write to a particular logger at a particular priority.
        Parameters:
        logger - the logger to write to
        priority - the priority at which to log
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Shutdown stream.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException - if an error occurs while closing the stream
      • write

        public void write​(int data)
                   throws java.io.IOException
        Write a single byte of data to output stream.
        Specified by:
        write in class java.io.OutputStream
        Parameters:
        data - the byte of data
        Throws:
        java.io.IOException - if an error occurs
      • flush

        public void flush()
                   throws java.io.IOException
        Flush data to underlying logger.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException - if an error occurs
      • checkValid

        private void checkValid()
                         throws java.io.IOException
        Make sure stream is valid.
        Throws:
        java.io.IOException - if an error occurs