Package org.apache.log4j
Class NewAsyncAppender
- java.lang.Object
-
- org.apache.log4j.AppenderSkeleton
-
- org.apache.log4j.NewAsyncAppender
-
- All Implemented Interfaces:
Appender,AppenderAttachable,OptionHandler
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:
NewAyncAppednerrequires DOMConfigurator, i.e. XML configuration format.- Since:
- 1.2.26
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classNewAsyncAppender.Worker
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicIntegerappenderCount(package private) AppenderAttachableImplappenders(package private) java.util.concurrent.BlockingQueue<LoggingEvent>blockingQueuestatic intDEFAULT_MAX_FLUSH_TIMEThe default maximum queue flush time allowed during appender stop.static intDEFAULT_QUEUE_SIZEThe default buffer size.(package private) intdiscardingThreshold(package private) booleanincludeCallerData(package private) intmaxFlushTime(package private) booleanneverBlock(package private) intqueueSize(package private) static intUNDEFINED(package private) NewAsyncAppender.Workerworker-
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
-
-
Constructor Summary
Constructors Constructor Description NewAsyncAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateOptions()Derived appenders should override this method if option structure requires it.voidaddAppender(Appender newAppender)Add an appender.protected voidappend(LoggingEvent event)Subclasses ofAppenderSkeletonshould implement this method to perform actual logging.voidclose()Release any resources allocated within the appender such as file handles, network connections, etc.java.util.EnumerationgetAllAppenders()Get all previously added appenders as an Enumeration.AppendergetAppender(java.lang.String name)Get an appender by name.intgetDiscardingThreshold()intgetMaxFlushTime()intgetQueueSize()booleanisAttached(Appender appender)Returnstrueif the specified appender is in list of attached attached,falseotherwise.(package private) booleanisClosed()protected booleanisDiscardable(LoggingEvent event)Events of level TRACE, DEBUG and INFO are deemed to be discardable.booleanisIncludeCallerData()booleanisNeverBlock()booleanisQueueBelowDiscardingThreshold()protected voidpreprocess(LoggingEvent eventObject)private voidput(LoggingEvent eventObject)private voidputUninterruptibly(LoggingEvent eventObject)voidremoveAllAppenders()Remove all previously added appenders.voidremoveAppender(java.lang.String name)Remove the appender with the name passed as parameter from the list of appenders.voidremoveAppender(Appender appender)Remove the appender passed as parameter from the list of appenders.booleanrequiresLayout()Configurators call this method to determine if the appender requires a layout.voidsetDiscardingThreshold(int discardingThreshold)voidsetIncludeCallerData(boolean includeCallerData)voidsetMaxFlushTime(int maxFlushTime)voidsetNeverBlock(boolean neverBlock)voidsetQueueSize(int queueSize)-
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
-
-
-
-
Field Detail
-
DEFAULT_QUEUE_SIZE
public static final int DEFAULT_QUEUE_SIZE
The default buffer size.- See Also:
- Constant Field Values
-
queueSize
int queueSize
-
DEFAULT_MAX_FLUSH_TIME
public static final int DEFAULT_MAX_FLUSH_TIME
The default maximum queue flush time allowed during appender stop. If the worker takes longer than this time it will exit, discarding any remaining items in the queue- See Also:
- Constant Field Values
-
maxFlushTime
int maxFlushTime
-
appenders
AppenderAttachableImpl appenders
-
appenderCount
java.util.concurrent.atomic.AtomicInteger appenderCount
-
blockingQueue
java.util.concurrent.BlockingQueue<LoggingEvent> blockingQueue
-
worker
NewAsyncAppender.Worker worker
-
neverBlock
boolean neverBlock
-
UNDEFINED
static final int UNDEFINED
- See Also:
- Constant Field Values
-
discardingThreshold
int discardingThreshold
-
includeCallerData
boolean includeCallerData
-
-
Method Detail
-
activateOptions
public void activateOptions()
Description copied from class:AppenderSkeletonDerived appenders should override this method if option structure requires it.- Specified by:
activateOptionsin interfaceOptionHandler- Overrides:
activateOptionsin classAppenderSkeleton
-
append
protected void append(LoggingEvent event)
Description copied from class:AppenderSkeletonSubclasses ofAppenderSkeletonshould implement this method to perform actual logging. See alsoAppenderSkeleton.doAppendmethod.- Specified by:
appendin classAppenderSkeleton
-
isQueueBelowDiscardingThreshold
public boolean isQueueBelowDiscardingThreshold()
-
isDiscardable
protected boolean isDiscardable(LoggingEvent event)
Events of level TRACE, DEBUG and INFO are deemed to be discardable.- Parameters:
event-- Returns:
- true if the event is of level TRACE, DEBUG or INFO false otherwise.
-
preprocess
protected void preprocess(LoggingEvent eventObject)
-
put
private void put(LoggingEvent eventObject)
-
putUninterruptibly
private void putUninterruptibly(LoggingEvent eventObject)
-
close
public void close()
Description copied from interface:AppenderRelease any resources allocated within the appender such as file handles, network connections, etc.It is a programming error to append to a closed appender.
-
isClosed
boolean isClosed()
-
requiresLayout
public boolean requiresLayout()
Description copied from interface:AppenderConfigurators call this method to determine if the appender requires a layout. If this method returnstrue, meaning that layout is required, then the configurator will configure an layout using the configuration information at its disposal. If this method returnsfalse, 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.- Specified by:
requiresLayoutin interfaceAppender
-
addAppender
public void addAppender(Appender newAppender)
Description copied from interface:AppenderAttachableAdd an appender.- Specified by:
addAppenderin interfaceAppenderAttachable
-
getAllAppenders
public java.util.Enumeration getAllAppenders()
Description copied from interface:AppenderAttachableGet all previously added appenders as an Enumeration.- Specified by:
getAllAppendersin interfaceAppenderAttachable
-
getAppender
public Appender getAppender(java.lang.String name)
Description copied from interface:AppenderAttachableGet an appender by name.- Specified by:
getAppenderin interfaceAppenderAttachable
-
isAttached
public boolean isAttached(Appender appender)
Description copied from interface:AppenderAttachableReturnstrueif the specified appender is in list of attached attached,falseotherwise.- Specified by:
isAttachedin interfaceAppenderAttachable
-
removeAllAppenders
public void removeAllAppenders()
Description copied from interface:AppenderAttachableRemove all previously added appenders.- Specified by:
removeAllAppendersin interfaceAppenderAttachable
-
removeAppender
public void removeAppender(Appender appender)
Description copied from interface:AppenderAttachableRemove the appender passed as parameter from the list of appenders.- Specified by:
removeAppenderin interfaceAppenderAttachable
-
removeAppender
public void removeAppender(java.lang.String name)
Description copied from interface:AppenderAttachableRemove the appender with the name passed as parameter from the list of appenders.- Specified by:
removeAppenderin interfaceAppenderAttachable
-
getQueueSize
public int getQueueSize()
-
setQueueSize
public void setQueueSize(int queueSize)
-
getDiscardingThreshold
public int getDiscardingThreshold()
-
setDiscardingThreshold
public void setDiscardingThreshold(int discardingThreshold)
-
getMaxFlushTime
public int getMaxFlushTime()
-
setMaxFlushTime
public void setMaxFlushTime(int maxFlushTime)
-
setNeverBlock
public void setNeverBlock(boolean neverBlock)
-
isNeverBlock
public boolean isNeverBlock()
-
isIncludeCallerData
public boolean isIncludeCallerData()
-
setIncludeCallerData
public void setIncludeCallerData(boolean includeCallerData)
-
-