org.perf4j.log4j
Class AsyncCoalescingStatisticsAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by org.perf4j.log4j.AsyncCoalescingStatisticsAppender
All Implemented Interfaces:
Appender, AppenderAttachable, OptionHandler

public class AsyncCoalescingStatisticsAppender
extends AppenderSkeleton
implements AppenderAttachable

This log4j Appender groups StopWatch log messages together to form GroupedTimingStatistics. At a scheduled interval the StopWatch log messages that currently exist in the buffer are pulled to create a single GroupedTimingStatistics instance that is then sent to any attached appenders.

Note that any LoggingEvents which do NOT contain StopWatch objects are discarded. Also, this appender stores logged messages in a bounded buffer before sending those messages to downstream appenders. If the buffer becomes full then subsequent logs will be discarded until the buffer has time to clear. You can access the number of discarded messages using the getNumDiscardedMessages() method.

Author:
Alex Devine

Field Summary
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
AsyncCoalescingStatisticsAppender()
           
 
Method Summary
 void activateOptions()
           
 void addAppender(Appender appender)
           
protected  void append(LoggingEvent event)
           
 void close()
           
 Enumeration getAllAppenders()
           
 Appender getAppender(String name)
           
 String getDownstreamLogLevel()
          The DownstreamLogLevel option gets the Level of the GroupedTimingStatistics LoggingEvent that is sent to downstream appenders.
 int getNumDiscardedMessages()
          Returns the number of StopWatch messages that have been discarded due to the queue being full.
 int getQueueSize()
          The QueueSize option is used to control the size of the internal queue used by this appender to store logged messages before they are sent to downstream appenders.
 long getTimeSlice()
          The TimeSlice option represents the length of time, in milliseconds, of the window in which appended LogEvents are coalesced to a single GroupedTimingStatistics and sent to downstream appenders.
 boolean isAttached(Appender appender)
           
 boolean isCreateRollupStatistics()
          The CreateRollupStatistics option is used to determine whether "rollup" statistics should be created.
protected  StopWatchParser newStopWatchParser()
          This helper method could potentially be overridden to return a different type of StopWatchParser that is used to parse the log messages send to this appender.
 void removeAllAppenders()
           
 void removeAppender(Appender appender)
           
 void removeAppender(String name)
           
 boolean requiresLayout()
           
 void setCreateRollupStatistics(boolean createRollupStatistics)
          Sets the value of the CreateRollupStatistics option.
 void setDownstreamLogLevel(String downstreamLogLevel)
          Sets the value of the DownstreamLogLevel option.
 void setQueueSize(int queueSize)
          Sets the value of the QueueSize option.
 void setTimeSlice(long timeSlice)
          Sets the value of the TimeSlice option.
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncCoalescingStatisticsAppender

public AsyncCoalescingStatisticsAppender()
Method Detail

getTimeSlice

public long getTimeSlice()
The TimeSlice option represents the length of time, in milliseconds, of the window in which appended LogEvents are coalesced to a single GroupedTimingStatistics and sent to downstream appenders. Defaults to 30,000 milliseconds.

Returns:
the TimeSlice option.

setTimeSlice

public void setTimeSlice(long timeSlice)
Sets the value of the TimeSlice option.

Parameters:
timeSlice - The new TimeSlice option, in milliseconds.

getDownstreamLogLevel

public String getDownstreamLogLevel()
The DownstreamLogLevel option gets the Level of the GroupedTimingStatistics LoggingEvent that is sent to downstream appenders. Since each GroupedTimingStatistics represents a view of a collection of single StopWatch timing event, each of which may have been logged at different levels, this appender needs to decide on a single Level to use to notify downstream appenders. Defaults to "INFO".

Returns:
The DownstreamLogLevel option as a String

setDownstreamLogLevel

public void setDownstreamLogLevel(String downstreamLogLevel)
Sets the value of the DownstreamLogLevel option. This String must be one of the defined Level constants.

Parameters:
downstreamLogLevel - The new DownstreamLogLevel option.

isCreateRollupStatistics

public boolean isCreateRollupStatistics()
The CreateRollupStatistics option is used to determine whether "rollup" statistics should be created. If the tag name of a StopWatch in a log message contains periods, then the GroupedTimingStatistics will be created as if each substring of the tag up to the period was also logged with a separate StopWatch instance. For example, suppose a StopWatch was logged with a tag of "requests.specificReq.PASS". For grouping purposes a StopWatch entry would be logged under each of the following tags: This allows you to view statistics at both an individual and aggregated level. If there were other StopWatch entries with a tag of "requests.specificReq.FAIL", then the data collected at the "requests.specificReq" level would include BOTH PASS and FAIL events.

Returns:
The CreateRollupStatistics option.

setCreateRollupStatistics

public void setCreateRollupStatistics(boolean createRollupStatistics)
Sets the value of the CreateRollupStatistics option.

Parameters:
createRollupStatistics - The new CreateRollupStatistics option.

getQueueSize

public int getQueueSize()
The QueueSize option is used to control the size of the internal queue used by this appender to store logged messages before they are sent to downstream appenders. Defaults to 1024. If set too small and the queue fills up, then logged StopWatches will be discarded. The number of discarded messages can be accessed using the getNumDiscardedMessages() method.

Returns:
The QueueSize option.

setQueueSize

public void setQueueSize(int queueSize)
Sets the value of the QueueSize option.

Parameters:
queueSize - The new QueueSize option.

activateOptions

public void activateOptions()
Specified by:
activateOptions in interface OptionHandler
Overrides:
activateOptions in class AppenderSkeleton

getNumDiscardedMessages

public int getNumDiscardedMessages()
Returns the number of StopWatch messages that have been discarded due to the queue being full.

Returns:
The number of discarded messages.

addAppender

public void addAppender(Appender appender)
Specified by:
addAppender in interface AppenderAttachable

getAllAppenders

public Enumeration getAllAppenders()
Specified by:
getAllAppenders in interface AppenderAttachable

getAppender

public Appender getAppender(String name)
Specified by:
getAppender in interface AppenderAttachable

isAttached

public boolean isAttached(Appender appender)
Specified by:
isAttached in interface AppenderAttachable

removeAllAppenders

public void removeAllAppenders()
Specified by:
removeAllAppenders in interface AppenderAttachable

removeAppender

public void removeAppender(Appender appender)
Specified by:
removeAppender in interface AppenderAttachable

removeAppender

public void removeAppender(String name)
Specified by:
removeAppender in interface AppenderAttachable

append

protected void append(LoggingEvent event)
Specified by:
append in class AppenderSkeleton

requiresLayout

public boolean requiresLayout()
Specified by:
requiresLayout in interface Appender
Specified by:
requiresLayout in class AppenderSkeleton

close

public void close()
Specified by:
close in interface Appender
Specified by:
close in class AppenderSkeleton

newStopWatchParser

protected StopWatchParser newStopWatchParser()
This helper method could potentially be overridden to return a different type of StopWatchParser that is used to parse the log messages send to this appender.

Returns:
A new StopWatchParser to use to parse log messages.


Copyright © 2008-2009 perf4j.org. All Rights Reserved.