org.apache.log.output

Class AsyncLogTarget

Implemented Interfaces:
Runnable, Closeable, ErrorAware, LogTarget

public class AsyncLogTarget
extends AbstractWrappingTarget
implements Runnable

An asynchronous LogTarget that sends entries on in another thread. It is the responsibility of the user of this class to start the thread etc.
 LogTarget mySlowTarget = ...;
 AsyncLogTarget asyncTarget = new AsyncLogTarget( mySlowTarget );
 Thread thread = new Thread( asyncTarget );
 thread.setPriority( Thread.MIN_PRIORITY );
 thread.start();

 logger.setLogTargets( new LogTarget[] { asyncTarget } );
 
Authors:
Avalon Development Team
Peter Donald

Field Summary

private LinkedList
m_list
private int
m_queueSize

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

m_closeWrapped, m_wrappedLogTarget

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

DEFAULT_ERROR_HANDLER, m_errorHandler, m_isOpen

Constructor Summary

AsyncLogTarget(LogTarget logTarget)
Creation of a new async log target.
AsyncLogTarget(LogTarget logTarget, boolean closeTarget)
Creation of a new async log target.
AsyncLogTarget(LogTarget logTarget, int queueSize)
Creation of a new async log target.
AsyncLogTarget(LogTarget logTarget, int queueSize, boolean closeTarget)
Creation of a new async log target.

Method Summary

void
doProcessEvent(LogEvent event)
Process a log event by adding it to queue.
void
run()
Thread startup.
void
setErrorHandler(ErrorHandler errorHandler)
Provide component with ErrorHandler.

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

close, getLogTarget

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

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

Field Details

m_list

private final LinkedList m_list

m_queueSize

private final int m_queueSize

Constructor Details

AsyncLogTarget

public AsyncLogTarget(LogTarget logTarget)
Creation of a new async log target.
Parameters:
logTarget - the underlying target

AsyncLogTarget

public AsyncLogTarget(LogTarget logTarget,
                      boolean closeTarget)
Creation of a new async log target.
Parameters:
logTarget - the underlying target
closeTarget - close the underlying target when this target is closed. This flag has no effect unless the logTarget implements Closeable.

AsyncLogTarget

public AsyncLogTarget(LogTarget logTarget,
                      int queueSize)
Creation of a new async log target.
Parameters:
logTarget - the underlying target
queueSize - the queue size

AsyncLogTarget

public AsyncLogTarget(LogTarget logTarget,
                      int queueSize,
                      boolean closeTarget)
Creation of a new async log target.
Parameters:
logTarget - the underlying target
queueSize - the queue size
closeTarget - close the underlying target when this target is closed. This flag has no effect unless the logTarget implements Closeable.

Method Details

doProcessEvent

public void doProcessEvent(LogEvent event)
Process a log event by adding it to queue.
Overrides:
doProcessEvent in interface AbstractTarget
Parameters:
event - the log event

run

public void run()
Thread startup.

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
Provide component with ErrorHandler.
Specified by:
setErrorHandler in interface ErrorAware
Overrides:
setErrorHandler in interface AbstractTarget
Parameters:
errorHandler - the errorHandler