public abstract class LoggerAwareOutputStream extends 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 and Description |
|---|---|
protected Logger |
m_logger
Logger reference |
| Constructor and Description |
|---|
LoggerAwareOutputStream(Logger logger)
Constructor, creates instance of class.
|
| Modifier and Type | Method and 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(String message)
Writes the message to the log.
|
void |
write(int b)
Writes a byte to the internal buffer.
|
write, writepublic LoggerAwareOutputStream(Logger logger)
logger - logger this output stream should usepublic void write(int b)
throws IOException
write in class OutputStreamb - character to writeIOException - if an error occursOutputStream.write(int)public void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOException - on errorOutputStream.flush()public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOException - if an IO error occursOutputStream.close()protected abstract void logMessage(String message)
message - message to be writtenCopyright © 2019. All rights reserved.