org.apache.log.util

Class LoggerOutputStream

public class LoggerOutputStream extends 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

Field Summary
booleanm_closed
Loggerm_logger
StringBufferm_output
Prioritym_priority
Constructor Summary
LoggerOutputStream(Logger logger, Priority priority)
Construct OutputStreamLogger to write to a particular logger at a particular priority.
Method Summary
voidcheckValid()
Make sure stream is valid.
voidclose()
Shutdown stream.
voidflush()
Flush data to underlying logger.
voidwrite(int data)
Write a single byte of data to output stream.

Field Detail

m_closed

private boolean m_closed

m_logger

private final Logger m_logger

m_output

private final StringBuffer m_output

m_priority

private final Priority m_priority

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

checkValid

private void checkValid()
Make sure stream is valid.

Throws: IOException if an error occurs

close

public void close()
Shutdown stream.

Throws: IOException if an error occurs while closing the stream

flush

public void flush()
Flush data to underlying logger.

Throws: IOException if an error occurs

write

public void write(int data)
Write a single byte of data to output stream.

Parameters: data the byte of data

Throws: IOException if an error occurs