org.tentackle.util
Class LoggerOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by org.tentackle.util.LoggerOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class LoggerOutputStream
extends ByteArrayOutputStream

Output stream for a logger.
Nice to catch e.printStackTrace(Stream)

Author:
harald

Field Summary
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
LoggerOutputStream(Logger logger)
          Creates a logger output stream with a default buffersize and org.tentackle.util.Level#SEVERE.
LoggerOutputStream(Logger logger, Logger.Level level)
          Creates a logger output stream with a default buffersize.
LoggerOutputStream(Logger logger, Logger.Level level, int size)
          Creates a logger output stream.
 
Method Summary
 void close()
          Closing a ByteArrayOutputStream has no effect.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
static void logException(Exception e)
          Logs an exception stacktrace to the logger with a default buffersize and org.tentackle.util.Level#SEVERE to the default logger of the util package.
static void logException(Exception e, Logger logger)
          Logs an exception stacktrace to the logger with a default buffersize and org.tentackle.util.Level#SEVERE.
static void logException(Exception e, Logger logger, Logger.Level level, int size)
          Logs an exception stacktrace to the logger.
 
Methods inherited from class java.io.ByteArrayOutputStream
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

LoggerOutputStream

public LoggerOutputStream(Logger logger,
                          Logger.Level level,
                          int size)
Creates a logger output stream.

Parameters:
logger - the logger
level - one of org.tentackle.util.Level#SEVERE, etc...
size - the buffersize

LoggerOutputStream

public LoggerOutputStream(Logger logger,
                          Logger.Level level)
Creates a logger output stream with a default buffersize.

Parameters:
logger - the logger
level - one of org.tentackle.util.Level#SEVERE, etc...

LoggerOutputStream

public LoggerOutputStream(Logger logger)
Creates a logger output stream with a default buffersize and org.tentackle.util.Level#SEVERE.

Parameters:
logger - the logger
Method Detail

flush

public void flush()
Description copied from class: java.io.OutputStream
Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

The flush method of OutputStream does nothing.

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

close

public void close()
Description copied from class: java.io.ByteArrayOutputStream
Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Specified by:
close in interface Closeable
Overrides:
close in class ByteArrayOutputStream

logException

public static void logException(Exception e,
                                Logger logger,
                                Logger.Level level,
                                int size)
Logs an exception stacktrace to the logger.

Parameters:
e - the exception
logger - the logger
level - the logging level
size - the buffersize

logException

public static void logException(Exception e,
                                Logger logger)
Logs an exception stacktrace to the logger with a default buffersize and org.tentackle.util.Level#SEVERE.

Parameters:
e - the exception
logger - the logger

logException

public static void logException(Exception e)
Logs an exception stacktrace to the logger with a default buffersize and org.tentackle.util.Level#SEVERE to the default logger of the util package.

Parameters:
e - the exception


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de