org.apache.log.output.io

Class StreamTarget

Implemented Interfaces:
Closeable, ErrorAware, LogTarget
Known Direct Subclasses:
FileTarget

public class StreamTarget
extends AbstractOutputTarget

A basic target that writes to an OutputStream.
Author:
Peter Donald

Field Summary

private String
m_encoding
The encoding to use when creating byte array for string, may be null.
private OutputStream
m_outputStream
OutputStream we are writing to.

Fields inherited from class org.apache.log.output.AbstractOutputTarget

m_formatter

Fields inherited from class org.apache.log.output.AbstractTarget

DEFAULT_ERROR_HANDLER, m_errorHandler, m_isOpen

Constructor Summary

StreamTarget(OutputStream outputStream, Formatter formatter)
Constructor that writes to a stream and uses a particular formatter.
StreamTarget(OutputStream outputStream, Formatter formatter, String encoding)
Constructor that writes to a stream and uses a particular formatter.

Method Summary

void
close()
Shutdown target.
protected void
setOutputStream(OutputStream outputStream)
Set the output stream.
protected void
shutdownStream()
Shutdown output stream.
protected void
write(String data)
Abstract method that will output event.

Methods inherited from class org.apache.log.output.AbstractOutputTarget

close, doProcessEvent, format, getFormatter, getHead, getTail, open, write, writeHead, writeTail

Methods inherited from class org.apache.log.output.AbstractTarget

close, doProcessEvent, getErrorHandler, isOpen, open, processEvent, setErrorHandler

Field Details

m_encoding

private String m_encoding
The encoding to use when creating byte array for string, may be null.

m_outputStream

private OutputStream m_outputStream
OutputStream we are writing to.

Constructor Details

StreamTarget

public StreamTarget(OutputStream outputStream,
                    Formatter formatter)
Constructor that writes to a stream and uses a particular formatter.
Parameters:
outputStream - the OutputStream to write to
formatter - the Formatter to use

StreamTarget

public StreamTarget(OutputStream outputStream,
                    Formatter formatter,
                    String encoding)
Constructor that writes to a stream and uses a particular formatter.
Parameters:
outputStream - the OutputStream to write to
formatter - the Formatter to use
encoding - Desired encoding to use when writing to the log, null implies the default system encoding.

Method Details

close

public void close()
Shutdown target. Attempting to write to target after close() will cause errors to be logged.
Specified by:
close in interface Closeable
Overrides:
close in interface AbstractOutputTarget

setOutputStream

protected void setOutputStream(OutputStream outputStream)
Set the output stream. Close down old stream and write tail if appropriate.
Parameters:
outputStream - the new OutputStream

shutdownStream

protected void shutdownStream()
Shutdown output stream.

write

protected void write(String data)
Abstract method that will output event.
Overrides:
write in interface AbstractOutputTarget
Parameters:
data - the data to be output