public abstract class LoggerAwareOutputStream
extends java.io.OutputStream
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 );
}
}
} );
| Modifier and Type | Field | Description |
|---|---|---|
private java.io.ByteArrayOutputStream |
bos |
Message buffer
|
protected org.apache.avalon.framework.logger.Logger |
m_logger |
Logger reference |
| Constructor | Description |
|---|---|
LoggerAwareOutputStream(org.apache.avalon.framework.logger.Logger logger) |
Constructor, creates instance of class.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Purposely flushes the stream, but doesn't close anything since the logger
is managed by another class.
|
void |
flush() |
Flushes this output stream, writing any buffered content to the log
|
protected abstract void |
logMessage(java.lang.String message) |
Writes the message to the log.
|
void |
write(int b) |
Writes a byte to the internal buffer.
|
private final java.io.ByteArrayOutputStream bos
protected final org.apache.avalon.framework.logger.Logger m_logger
Logger referencepublic LoggerAwareOutputStream(org.apache.avalon.framework.logger.Logger logger)
logger - logger this output stream should usepublic void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamb - character to writejava.io.IOException - if an error occursOutputStream.write(int)public void flush()
throws java.io.IOException
flush in class java.io.OutputStreamjava.io.IOException - on errorOutputStream.flush()public void close()
throws java.io.IOException
close in class java.io.OutputStreamjava.io.IOException - if an IO error occursOutputStream.close()protected abstract void logMessage(java.lang.String message)
message - message to be written