Class LoggerAwareOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.avalon.framework.logger.LoggerAwareOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public abstract class LoggerAwareOutputStream extends java.io.OutputStreamLogger aware output stream, characters written to thisOutputStreamare 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
-
-
Constructor Summary
Constructors Constructor Description LoggerAwareOutputStream(org.apache.avalon.framework.logger.Logger logger)Constructor, creates instance of class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Purposely flushes the stream, but doesn't close anything since the logger is managed by another class.voidflush()Flushes this output stream, writing any buffered content to the logprotected abstract voidlogMessage(java.lang.String message)Writes the message to the log.voidwrite(int b)Writes a byte to the internal buffer.
-
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOExceptionWrites a byte to the internal buffer. If a newline character is encountered, then the buffer is sent to the logger.- Specified by:
writein classjava.io.OutputStream- Parameters:
b- character to write- Throws:
java.io.IOException- if an error occurs- See Also:
OutputStream.write(int)
-
flush
public void flush() throws java.io.IOExceptionFlushes this output stream, writing any buffered content to the log- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException- on error- See Also:
OutputStream.flush()
-
close
public void close() throws java.io.IOExceptionPurposely flushes the stream, but doesn't close anything since the logger is managed by another class.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException- if an IO error occurs- See Also:
OutputStream.close()
-
logMessage
protected abstract void logMessage(java.lang.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- message to be written
-
-