info.aduna.autofocus.util
Class LoggingOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by info.aduna.autofocus.util.LoggingOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class LoggingOutputStream
extends ByteArrayOutputStream

An OutputStream that writes contents to a Logger upon each call to flush().

This code was derived from code found at http://blogs.sun.com/nickstephen/entry/java_redirecting_system_out_and, changing the use of java.util.logging with SLF4J.

Warning: when using this class to redirect System.out and System.err to a Logger, take extreme care that the Logger specified to the constructor does not print to System.out or System.err (as e.g. the SimpleLogger does), or you will run into an infinite loop.


Field Summary
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
LoggingOutputStream(org.slf4j.Logger logger, boolean warn)
           
 
Method Summary
 void flush()
          Writes the existing contents of the OutputStream to the Logger.
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LoggingOutputStream

public LoggingOutputStream(org.slf4j.Logger logger,
                           boolean warn)
Method Detail

flush

public void flush()
           throws IOException
Writes the existing contents of the OutputStream to the Logger.

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException


Copyright © 1997-2008 Aduna. All Rights Reserved.