org.apache.log4j

Class AsyncAppender

Implemented Interfaces:
Appender, AppenderAttachable, OptionHandler

public class AsyncAppender
extends AppenderSkeleton
implements AppenderAttachable

The AsyncAppender lets users log events asynchronously. It uses a bounded buffer to store logging events.

The AsyncAppender will collect the events sent to it and then dispatch them to all the appenders that are attached to it. You can attach multiple appenders to an AsyncAppender.

The AsyncAppender uses a separate thread to serve the events in its bounded buffer.

Refer to the results in org.apache.log4j.performance.Logging for the impact of using this appender.

Important note: The AsyncAppender can only be script configured using the DOMConfigurator.

Author:
Ceki Gülcü
Since:
0.9.1

Field Summary

static int
DEFAULT_BUFFER_SIZE
The default buffer size is set to 128 events.

Fields inherited from class org.apache.log4j.AppenderSkeleton

closed, errorHandler, headFilter, layout, name, tailFilter, threshold

Constructor Summary

AsyncAppender()

Method Summary

void
addAppender(Appender newAppender)
Add an appender.
void
append(LoggingEvent event)
Subclasses of AppenderSkeleton should implement this method to perform actual logging.
void
close()
Close this AsyncAppender by interrupting the dispatcher thread which will process all pending events before exiting.
Enumeration
getAllAppenders()
Get all previously added appenders as an Enumeration.
Appender
getAppender(String name)
Get an appender by name.
int
getBufferSize()
Returns the current value of the BufferSize option.
boolean
getLocationInfo()
Returns the current value of the LocationInfo option.
boolean
isAttached(Appender appender)
Is the appender passed as parameter attached to this category?
void
removeAllAppenders()
Remove all previously added appenders.
void
removeAppender(String name)
Remove the appender with the name passed as parameter from the list of appenders.
void
removeAppender(Appender appender)
Remove the appender passed as parameter from the list of appenders.
boolean
requiresLayout()
The AsyncAppender does not require a layout.
void
setBufferSize(int size)
The BufferSize option takes a non-negative integer value.
void
setLocationInfo(boolean flag)
The LocationInfo option takes a boolean value.

Methods inherited from class org.apache.log4j.AppenderSkeleton

activateOptions, addFilter, append, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold

Field Details

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default buffer size is set to 128 events.
Field Value:
128

Constructor Details

AsyncAppender

public AsyncAppender()

Method Details

addAppender

public void addAppender(Appender newAppender)
Add an appender.
Specified by:
addAppender in interface AppenderAttachable

append

public void append(LoggingEvent event)
Subclasses of AppenderSkeleton should implement this method to perform actual logging. See also AppenderSkeleton.doAppend method.
Overrides:
append in interface AppenderSkeleton
Since:
0.9.0

close

public void close()
Close this AsyncAppender by interrupting the dispatcher thread which will process all pending events before exiting.
Specified by:
close in interface Appender

getAllAppenders

public Enumeration getAllAppenders()
Get all previously added appenders as an Enumeration.
Specified by:
getAllAppenders in interface AppenderAttachable

getAppender

public Appender getAppender(String name)
Get an appender by name.
Specified by:
getAppender in interface AppenderAttachable

getBufferSize

public int getBufferSize()
Returns the current value of the BufferSize option.

getLocationInfo

public boolean getLocationInfo()
Returns the current value of the LocationInfo option.

isAttached

public boolean isAttached(Appender appender)
Is the appender passed as parameter attached to this category?
Specified by:
isAttached in interface AppenderAttachable

removeAllAppenders

public void removeAllAppenders()
Remove all previously added appenders.
Specified by:
removeAllAppenders in interface AppenderAttachable

removeAppender

public void removeAppender(String name)
Remove the appender with the name passed as parameter from the list of appenders.
Specified by:
removeAppender in interface AppenderAttachable

removeAppender

public void removeAppender(Appender appender)
Remove the appender passed as parameter from the list of appenders.
Specified by:
removeAppender in interface AppenderAttachable

requiresLayout

public boolean requiresLayout()
The AsyncAppender does not require a layout. Hence, this method always returns false.
Specified by:
requiresLayout in interface Appender

setBufferSize

public void setBufferSize(int size)

setLocationInfo

public void setLocationInfo(boolean flag)
The LocationInfo option takes a boolean value. By default, it is set to false which means there will be no effort to extract the location information related to the event. As a result, the event that will be ultimately logged will likely to contain the wrong location information (if present in the log format).

Location information extraction is comparatively very slow and should be avoided unless performance is not a concern.


Copyright 2000-2005 Apache Software Foundation.