org.perf4j.log4j
Class AsyncCoalescingStatisticsAppender

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

public class AsyncCoalescingStatisticsAppender
extends org.apache.log4j.AppenderSkeleton
implements org.apache.log4j.spi.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.

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(org.apache.log4j.Appender appender)
           
protected  void append(org.apache.log4j.spi.LoggingEvent event)
           
 void close()
           
 java.util.Enumeration getAllAppenders()
           
 org.apache.log4j.Appender getAppender(java.lang.String name)
           
 java.lang.String getDownstreamLogLevel()
          The DownstreamLogLevel option gets the Level of the GroupedTimingStatistics LoggingEvent that is 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(org.apache.log4j.Appender appender)
           
 boolean isCreateRollupStatistics()
          The CreateRollupStatistics option is used to determine whether "rollup" statistics should be created.
 void removeAllAppenders()
           
 void removeAppender(org.apache.log4j.Appender appender)
           
 void removeAppender(java.lang.String name)
           
 boolean requiresLayout()
           
 void setCreateRollupStatistics(boolean createRollupStatistics)
          Sets the value of the CreateRollupStatistics option.
 void setDownstreamLogLevel(java.lang.String downstreamLogLevel)
          Sets the value of the DownstreamLogLevel 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 java.lang.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(java.lang.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.

activateOptions

public void activateOptions()
Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler
Overrides:
activateOptions in class org.apache.log4j.AppenderSkeleton

addAppender

public void addAppender(org.apache.log4j.Appender appender)
Specified by:
addAppender in interface org.apache.log4j.spi.AppenderAttachable

getAllAppenders

public java.util.Enumeration getAllAppenders()
Specified by:
getAllAppenders in interface org.apache.log4j.spi.AppenderAttachable

getAppender

public org.apache.log4j.Appender getAppender(java.lang.String name)
Specified by:
getAppender in interface org.apache.log4j.spi.AppenderAttachable

isAttached

public boolean isAttached(org.apache.log4j.Appender appender)
Specified by:
isAttached in interface org.apache.log4j.spi.AppenderAttachable

removeAllAppenders

public void removeAllAppenders()
Specified by:
removeAllAppenders in interface org.apache.log4j.spi.AppenderAttachable

removeAppender

public void removeAppender(org.apache.log4j.Appender appender)
Specified by:
removeAppender in interface org.apache.log4j.spi.AppenderAttachable

removeAppender

public void removeAppender(java.lang.String name)
Specified by:
removeAppender in interface org.apache.log4j.spi.AppenderAttachable

append

protected void append(org.apache.log4j.spi.LoggingEvent event)
Specified by:
append in class org.apache.log4j.AppenderSkeleton

requiresLayout

public boolean requiresLayout()
Specified by:
requiresLayout in interface org.apache.log4j.Appender
Specified by:
requiresLayout in class org.apache.log4j.AppenderSkeleton

close

public void close()
Specified by:
close in interface org.apache.log4j.Appender
Specified by:
close in class org.apache.log4j.AppenderSkeleton


Copyright © 2008 perf4j.org. All Rights Reserved.