Top Description Fields Constructors Methods
org.apache.avalon.framework.logger

public abstract Class LoggerAwareOutputStream

extends OutputStream
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .OutputStream

Logger aware output stream, characters written to this OutputStream are buffered until a newline character is encountered, or a flush() is called.

Extend to specify the log method that the message should be invoked. eg:

setOutputStream( new LoggerAwareOutputStream( getLogger() ) {
    protected void logMessage( String message )
    {
        if ( m_logger.isDebugEnabled() )
        {
            m_logger.debug( message );
        }
    }
} );
Author
Marcus Crafter
Since
Nov 19, 2004 7:03:50 PM
Version
$Revision:$

Field Summary

Modifier and TypeField and Description
private final ByteArrayOutputStream
bos

Message buffer

protected final Logger
m_logger

Logger reference

Constructor Summary

AccessConstructor and Description
public
LoggerAwareOutputStream(Logger
logger this output stream should use
logger
)

Constructor, creates instance of class.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Purposely flushes the stream, but doesn't close anything since the logger is managed by another class.
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream, writing any buffered content to the log
protected abstract void
logMessage(String
message to be written
message
)

Writes the message to the log.

public void
write(int
character to write
b
)

Implements abstract java.io.OutputStream.write.

Writes a byte to the internal buffer.
Inherited from java.io.OutputStream:
nullOutputStreamwritewrite

Field Detail

bosback to summary
private final ByteArrayOutputStream bos

Message buffer

m_loggerback to summary
protected final Logger m_logger

Logger reference

Constructor Detail

LoggerAwareOutputStreamback to summary
public LoggerAwareOutputStream(Logger logger)

Constructor, creates instance of class.

Parameters
logger:Logger

logger this output stream should use

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Purposely flushes the stream, but doesn't close anything since the logger is managed by another class.

Exceptions
IOException:
if an IO error occurs
See Also
java.io.OutputStream#close()
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream, writing any buffered content to the log

Exceptions
IOException:
on error
See Also
java.io.OutputStream#flush()
logMessageback to summary
protected abstract void logMessage(String message)

Writes the message to the log. Subclasses should override this method to send the message to the log level they require.

Parameters
message:String

message to be written

writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Writes a byte to the internal buffer. If a newline character is encountered, then the buffer is sent to the logger.

Parameters
b:int

character to write

Exceptions
IOException:
if an error occurs
See Also
java.io.OutputStream#write(int)