org.apache.log.output

Class AbstractOutputTarget

Implemented Interfaces:
Closeable, ErrorAware, LogTarget
Known Direct Subclasses:
DatagramOutputTarget, NullOutputLogTarget, ServletOutputLogTarget, SMTPOutputLogTarget, SocketOutputTarget, StreamTarget, WriterTarget

public abstract class AbstractOutputTarget
extends AbstractTarget

Abstract output target. Any new output target that is writing to a single connected resource should extend this class directly or indirectly.
Authors:
Avalon Development Team
Peter Donald

Field Summary

private Formatter
m_formatter
Formatter for target.

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

DEFAULT_ERROR_HANDLER, m_errorHandler, m_isOpen

Constructor Summary

AbstractOutputTarget()
Parameterless constructor.
AbstractOutputTarget(Formatter formatter)
Creation of a new abstract output target instance.

Method Summary

void
close()
Shutdown target.
protected void
doProcessEvent(LogEvent event)
Process a log event.
private String
format(LogEvent event)
Helper method to format an event into a string, using the formatter if available.
protected Formatter
getFormatter()
Returns the Formatter.
private String
getHead()
Helper method to retrieve head for log session.
private String
getTail()
Helper method to retrieve tail for log session.
protected void
open()
Startup log session.
protected void
write(String data)
Abstract method to write data.
private void
writeHead()
Helper method to write out log head.
private void
writeTail()
Helper method to write out log tail.

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

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

Field Details

m_formatter

private Formatter m_formatter
Formatter for target.

Constructor Details

AbstractOutputTarget

public AbstractOutputTarget()
Parameterless constructor.

AbstractOutputTarget

public AbstractOutputTarget(Formatter formatter)
Creation of a new abstract output target instance.
Parameters:
formatter - the formatter to apply

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 AbstractTarget

doProcessEvent

protected void doProcessEvent(LogEvent event)
Process a log event.
Overrides:
doProcessEvent in interface AbstractTarget
Parameters:
event - the event to process

format

private String format(LogEvent event)
Helper method to format an event into a string, using the formatter if available.
Parameters:
event - the LogEvent
Returns:
the formatted string

getFormatter

protected Formatter getFormatter()
Returns the Formatter.

getHead

private String getHead()
Helper method to retrieve head for log session. TODO: Extract from formatter
Returns:
the head string

getTail

private String getTail()
Helper method to retrieve tail for log session. TODO: Extract from formatter
Returns:
the head string

open

protected void open()
Startup log session.
Overrides:
open in interface AbstractTarget

write

protected void write(String data)
Abstract method to write data.
Parameters:
data - the data to be output

writeHead

private void writeHead()
Helper method to write out log head. The head initiates a session of logging.

writeTail

private void writeTail()
Helper method to write out log tail. The tail completes a session of logging.