org.perf4j.logback
Class AsyncCoalescingStatisticsAppender

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>
          extended by org.perf4j.logback.AsyncCoalescingStatisticsAppender
All Implemented Interfaces:
ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent>, ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>, ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.FilterAttachable<ch.qos.logback.classic.spi.LoggingEvent>, ch.qos.logback.core.spi.LifeCycle

public class AsyncCoalescingStatisticsAppender
extends ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>
implements ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>

This logback 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, Xu Huisheng

Field Summary
 
Fields inherited from class ch.qos.logback.core.AppenderBase
layout, name, started
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
AsyncCoalescingStatisticsAppender()
           
 
Method Summary
 void addAppender(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent> newAppender)
           
protected  void append(ch.qos.logback.classic.spi.LoggingEvent event)
           
 void detachAndStopAllAppenders()
           
 boolean detachAppender(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent> appender)
           
 boolean detachAppender(String name)
           
 ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent> 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.
 String getStopWatchParserClassName()
          The StopWatchParserClassName option is used to determine the class used to parse stop watch messages into StopWatch instances.
 long getTimeSlice()
          The TimeSlice option represents the length of time, in milliseconds, of the window in which appended LoggingEvents are coalesced to a single GroupedTimingStatistics and sent to downstream appenders.
 boolean isAttached(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent> appender)
           
 boolean isCreateRollupStatistics()
          The CreateRollupStatistics option is used to determine whether "rollup" statistics should be created.
 Iterator<ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent>> iteratorForAppenders()
           
protected  GenericAsyncCoalescingStatisticsAppender newGenericAsyncCoalescingStatisticsAppender()
          Creates the new GenericAsyncCoalescingStatisticsAppender that this instance will wrap.
 void setCreateRollupStatistics(boolean createRollupStatistics)
          Sets the value of the CreateRollupStatistics option.
 void setDownstreamLogLevel(String downstreamLogLevel)
          Sets the value of the DownstreamLogLevel option.
 void setName(String name)
           
 void setQueueSize(int queueSize)
          Sets the value of the QueueSize option.
 void setStopWatchParserClassName(String stopWatchParserClassName)
          Sets the value of the StopWatchParserClassName option.
 void setTimeSlice(long timeSlice)
          Sets the value of the TimeSlice option.
 void start()
           
 void stop()
           
 
Methods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getFirstFilter, getLayout, getName, isStarted, setLayout, toString
 
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getStatusManager, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
 

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 LoggingEvents 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.

getStopWatchParserClassName

public String getStopWatchParserClassName()
The StopWatchParserClassName option is used to determine the class used to parse stop watch messages into StopWatch instances. This defaults to the standard "org.perf4j.helpers.StopWatchParser" class.

Returns:
The StopWatchParserClassName option.

setStopWatchParserClassName

public void setStopWatchParserClassName(String stopWatchParserClassName)
Sets the value of the StopWatchParserClassName option.

Parameters:
stopWatchParserClassName - The new StopWatchParserClassName option.

setName

public void setName(String name)
Specified by:
setName in interface ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent>
Overrides:
setName in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>

start

public void start()
Specified by:
start in interface ch.qos.logback.core.spi.LifeCycle
Overrides:
start in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>

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(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent> newAppender)
Specified by:
addAppender in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>

iteratorForAppenders

public Iterator<ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent>> iteratorForAppenders()
Specified by:
iteratorForAppenders in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>

getAppender

public ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent> getAppender(String name)
Specified by:
getAppender in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>

isAttached

public boolean isAttached(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent> appender)
Specified by:
isAttached in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>

detachAndStopAllAppenders

public void detachAndStopAllAppenders()
Specified by:
detachAndStopAllAppenders in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>

detachAppender

public boolean detachAppender(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.LoggingEvent> appender)
Specified by:
detachAppender in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>

detachAppender

public boolean detachAppender(String name)
Specified by:
detachAppender in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.LoggingEvent>

append

protected void append(ch.qos.logback.classic.spi.LoggingEvent event)
Specified by:
append in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>

stop

public void stop()
Specified by:
stop in interface ch.qos.logback.core.spi.LifeCycle
Overrides:
stop in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.LoggingEvent>

newGenericAsyncCoalescingStatisticsAppender

protected GenericAsyncCoalescingStatisticsAppender newGenericAsyncCoalescingStatisticsAppender()
Creates the new GenericAsyncCoalescingStatisticsAppender that this instance will wrap.

Returns:
The newly created GenericAsyncCoalescingStatisticsAppender.


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