org.apache.log4j

Class AsyncAppender

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 {@link org.apache.log4j.performance.Logging} for the impact of using this appender.

Important note: The AsyncAppender can only be script configured using the {@link org.apache.log4j.xml.DOMConfigurator}.

Since: 0.9.1

Author: Ceki Gülcü

Field Summary
static intDEFAULT_BUFFER_SIZE
The default buffer size is set to 128 events.
Constructor Summary
AsyncAppender()
Method Summary
voidaddAppender(Appender newAppender)
voidappend(LoggingEvent event)
voidclose()
Close this AsyncAppender by interrupting the dispatcher thread which will process all pending events before exiting.
EnumerationgetAllAppenders()
AppendergetAppender(String name)
intgetBufferSize()
Returns the current value of the BufferSize option.
booleangetLocationInfo()
Returns the current value of the LocationInfo option.
booleanisAttached(Appender appender)
Is the appender passed as parameter attached to this category?
voidremoveAllAppenders()
voidremoveAppender(Appender appender)
voidremoveAppender(String name)
booleanrequiresLayout()
The AsyncAppender does not require a layout.
voidsetBufferSize(int size)
The BufferSize option takes a non-negative integer value.
voidsetLocationInfo(boolean flag)
The LocationInfo option takes a boolean value.

Field Detail

DEFAULT_BUFFER_SIZE

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

Constructor Detail

AsyncAppender

public AsyncAppender()

Method Detail

addAppender

public void addAppender(Appender newAppender)

append

public void append(LoggingEvent event)

close

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

getAllAppenders

public Enumeration getAllAppenders()

getAppender

public Appender getAppender(String name)

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?

removeAllAppenders

public void removeAllAppenders()

removeAppender

public void removeAppender(Appender appender)

removeAppender

public void removeAppender(String name)

requiresLayout

public boolean requiresLayout()
The AsyncAppender does not require a layout. Hence, this method always returns false.

setBufferSize

public void setBufferSize(int size)
The BufferSize option takes a non-negative integer value. This integer value determines the maximum size of the bounded buffer. Increasing the size of the buffer is always safe. However, if an existing buffer holds unwritten elements, then decreasing the buffer size will result in event loss. Nevertheless, while script configuring the AsyncAppender, it is safe to set a buffer size smaller than the {@link #DEFAULT_BUFFER_SIZE default buffer size} because configurators guarantee that an appender cannot be used before being completely configured.

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.