public class NewAsyncAppender extends AppenderSkeleton implements AppenderAttachable
An asynchronous appender closely reproducing the behaviour of logback's AsyncAppender
.
See Logback's AsyncAppender documentation for configuration options.
Here is a sample configuration file forNewAsyncAppender
.
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name="FILE" class="org.apache.log4j.FileAppender"> <param name="File" value="/tmp/foobar.log" /> <param name="Append" value="false" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/> </layout> </appender> <appender name="ASYNC" class="org.apache.log4j.NewAsyncAppender"> <param name="QueueSize" value="512"/> <appender-ref ref="FILE"/> </appender> <root> <level value="info"/> <appender-ref ref="ASYNC"/> </root> </log4j:configuration>
Note: NewAyncAppedner
requires DOMConfigurator, i.e. XML configuration format.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_FLUSH_TIME
The default maximum queue flush time allowed during appender stop.
|
static int |
DEFAULT_QUEUE_SIZE
The default buffer size.
|
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
Constructor and Description |
---|
NewAsyncAppender() |
Modifier and Type | Method and Description |
---|---|
void |
activateOptions()
Derived appenders should override this method if option structure requires it.
|
void |
addAppender(Appender newAppender)
Add an appender.
|
protected void |
append(LoggingEvent event)
Subclasses of
AppenderSkeleton should implement this method to perform actual logging. |
void |
close()
Release any resources allocated within the appender such as file handles, network connections, etc.
|
Enumeration |
getAllAppenders()
Get all previously added appenders as an Enumeration.
|
Appender |
getAppender(String name)
Get an appender by name.
|
int |
getDiscardingThreshold() |
int |
getMaxFlushTime() |
int |
getQueueSize() |
boolean |
isAttached(Appender appender)
Returns
true if the specified appender is in list of attached attached, false
otherwise. |
protected boolean |
isDiscardable(LoggingEvent event)
Events of level TRACE, DEBUG and INFO are deemed to be discardable.
|
boolean |
isIncludeCallerData() |
boolean |
isNeverBlock() |
boolean |
isQueueBelowDiscardingThreshold() |
protected void |
preprocess(LoggingEvent eventObject) |
void |
removeAllAppenders()
Remove all previously added appenders.
|
void |
removeAppender(Appender appender)
Remove the appender passed as parameter from the list of appenders.
|
void |
removeAppender(String name)
Remove the appender with the name passed as parameter from the list of appenders.
|
boolean |
requiresLayout()
Configurators call this method to determine if the appender requires a layout.
|
void |
setDiscardingThreshold(int discardingThreshold) |
void |
setIncludeCallerData(boolean includeCallerData) |
void |
setMaxFlushTime(int maxFlushTime) |
void |
setNeverBlock(boolean neverBlock) |
void |
setQueueSize(int queueSize) |
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
public static final int DEFAULT_QUEUE_SIZE
public static final int DEFAULT_MAX_FLUSH_TIME
public void activateOptions()
AppenderSkeleton
activateOptions
in interface OptionHandler
activateOptions
in class AppenderSkeleton
protected void append(LoggingEvent event)
AppenderSkeleton
AppenderSkeleton
should implement this method to perform actual logging. See also
AppenderSkeleton.doAppend
method.append
in class AppenderSkeleton
public boolean isQueueBelowDiscardingThreshold()
protected boolean isDiscardable(LoggingEvent event)
event
- protected void preprocess(LoggingEvent eventObject)
public void close()
Appender
It is a programming error to append to a closed appender.
public boolean requiresLayout()
Appender
true
, meaning that layout is required, then the configurator will configure an layout using the
configuration information at its disposal. If this method returns
false
, meaning that a layout is not required, then layout
configuration will be skipped even if there is available layout configuration information at the disposal of the
configurator..
In the rather exceptional case, where the appender implementation admits a layout but can also work without it,
then the appender should return
true
.
requiresLayout
in interface Appender
public void addAppender(Appender newAppender)
AppenderAttachable
addAppender
in interface AppenderAttachable
public Enumeration getAllAppenders()
AppenderAttachable
getAllAppenders
in interface AppenderAttachable
public Appender getAppender(String name)
AppenderAttachable
getAppender
in interface AppenderAttachable
public boolean isAttached(Appender appender)
AppenderAttachable
true
if the specified appender is in list of attached attached, false
otherwise.isAttached
in interface AppenderAttachable
public void removeAllAppenders()
AppenderAttachable
removeAllAppenders
in interface AppenderAttachable
public void removeAppender(Appender appender)
AppenderAttachable
removeAppender
in interface AppenderAttachable
public void removeAppender(String name)
AppenderAttachable
removeAppender
in interface AppenderAttachable
public int getQueueSize()
public void setQueueSize(int queueSize)
public int getDiscardingThreshold()
public void setDiscardingThreshold(int discardingThreshold)
public int getMaxFlushTime()
public void setMaxFlushTime(int maxFlushTime)
public void setNeverBlock(boolean neverBlock)
public boolean isNeverBlock()
public boolean isIncludeCallerData()
public void setIncludeCallerData(boolean includeCallerData)
Copyright © 1999–2024 QOS.CH Sarl (Switzerland). All rights reserved.