Class LoggerAwareOutputStream
java.lang.Object
java.io.OutputStream
org.apache.avalon.framework.logger.LoggerAwareOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
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 ); } } } );
- Since:
- Nov 19, 2004 7:03:50 PM
- Version:
- $Revision:$
- Author:
- Marcus Crafter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteArrayOutputStream
Message bufferprotected final org.apache.avalon.framework.logger.Logger
Logger
reference -
Constructor Summary
ConstructorsConstructorDescriptionLoggerAwareOutputStream
(org.apache.avalon.framework.logger.Logger logger) Constructor, creates instance of class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 logprotected abstract void
logMessage
(String message) Writes the message to the log.void
write
(int b) Writes a byte to the internal buffer.Methods inherited from class java.io.OutputStream
nullOutputStream, write, write
-
Field Details
-
bos
Message buffer -
m_logger
protected final org.apache.avalon.framework.logger.Logger m_loggerLogger
reference
-
-
Constructor Details
-
LoggerAwareOutputStream
public LoggerAwareOutputStream(org.apache.avalon.framework.logger.Logger logger) Constructor, creates instance of class.- Parameters:
logger
- logger this output stream should use
-
-
Method Details
-
write
Writes a byte to the internal buffer. If a newline character is encountered, then the buffer is sent to the logger.- Specified by:
write
in classOutputStream
- Parameters:
b
- character to write- Throws:
IOException
- if an error occurs- See Also:
-
flush
Flushes this output stream, writing any buffered content to the log- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- on error- See Also:
-
close
Purposely flushes the stream, but doesn't close anything since the logger is managed by another class.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
- if an IO error occurs- See Also:
-
logMessage
Writes the message to the log. Subclasses should override this method to send the message to the log level they require.- Parameters:
message
- message to be written
-