eu.larkc.core.data.util
Class LoggingOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by eu.larkc.core.data.util.LoggingOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class LoggingOutputStream
extends java.io.ByteArrayOutputStream

An OutputStream that stores each line after a flush(). The stored contents is then written to a Logger by calling one of the printLogAs* methods. The logging messages can not be logged immediately because it is likely that the System.out (stdout) stream is redirected and can thus not be used by the logger (Class derived from here with the permission of the author).

Author:
Christoph Fuchs

Constructor Summary
LoggingOutputStream(org.slf4j.Logger logger)
          Constructor
 
Method Summary
 void flush()
          upon flush() write the existing contents of the OutputStream to the logger as a log record.
 void printLogAsDebug()
          Prints the saved log messages as debug messages.
 void printLogAsError()
          Prints the saved log messages as error messages.
 void printLogAsInfo()
          Prints the saved log messages as info messages.
 void printLogAsTrace()
          Prints the saved log messages as trace messages.
 void printLogAsWarn()
          Prints the saved log messages as warning messages.
 
Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, write, write, writeTo
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LoggingOutputStream

public LoggingOutputStream(org.slf4j.Logger logger)
Constructor

Parameters:
logger - Logger to write to
Method Detail

flush

public void flush()
           throws java.io.IOException
upon flush() write the existing contents of the OutputStream to the logger as a log record.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - in case of error

printLogAsDebug

public void printLogAsDebug()
Prints the saved log messages as debug messages.


printLogAsInfo

public void printLogAsInfo()
Prints the saved log messages as info messages.


printLogAsWarn

public void printLogAsWarn()
Prints the saved log messages as warning messages.


printLogAsError

public void printLogAsError()
Prints the saved log messages as error messages.


printLogAsTrace

public void printLogAsTrace()
Prints the saved log messages as trace messages.