org.perf4j.log4j
Class StatisticsCsvLayout

java.lang.Object
  extended by org.apache.log4j.Layout
      extended by org.perf4j.log4j.StatisticsCsvLayout
All Implemented Interfaces:
OptionHandler

public class StatisticsCsvLayout
extends Layout
implements OptionHandler

A layout that outputs GroupedTimingStatistics instances as comma-separated values. Thus, this layout is designed to be attached to appenders that are themselves attached to an AsyncCoalescingStatisticsAppender.

By default, each GroupedTimingStatistics object is output as a bunch of lines, with one line for each tagged TimingStatistics instance contained within the GroupedTimingStatistics object. The following "columns" are output, separated by commas:

  1. tag - the tag name of the code block that the statistics refer to
  2. start - the start time of timing window
  3. stop - the stop time of the timing window
  4. mean - the mean execution time of stop watch logs that completed in the timing window
  5. min - the min execution time of stop watch logs that completed in the timing window
  6. max - the max execution time of stop watch logs that completed in the timing window
  7. stddev - the standard deviation of the execution times of stop watch logs that completed in the timing window
  8. count - the count of stop watch logs that completed during the timing window

You can modify the columns output using the Columns option. For example, you could specify the Columns option as "tag,start,stop,mean,count" to only output those specified values. In addition to the values specified above you can also use "tps" to output transactions per second.

In addition to the default output of one line per tag for each GroupedTimingStatistics object, this layout also supports a Pivot option which outputs just a single line for an entire GroupedTimingStatistics object. When pivot is true you should set the Columns to specify the values from the specific tags you want to output. For example, setting Pivot to true and setting Columns to "start,stop,codeBlock1Mean,codeBlock2Mean" would cause, for each GroupedTimingStatistics object, a single line to be output with the start and stop times of the window, the mean execution time for all stop watch logs with a codeBlock1 tag, and the mean execution time for all stop watch logs with a codeBlock2 tag.

Author:
Alex Devine

Field Summary
protected  GroupedTimingStatisticsCsvFormatter csvFormatter
          The csvFormatter is created in the activateOptions() method.
 
Fields inherited from class org.apache.log4j.Layout
LINE_SEP, LINE_SEP_LEN
 
Constructor Summary
StatisticsCsvLayout()
           
 
Method Summary
 void activateOptions()
           
 String format(LoggingEvent event)
           
 String getColumns()
          The Columns option is a comma-separated list of the values that should be output for each line that is printed.
 boolean ignoresThrowable()
          This layout ignores Throwables set on the LoggingEvent.
 boolean isPivot()
          The Pivot option, which is false by default, determines whether or not a single line will be output for each GroupedTimingStatistics object, or whether one line for each tag within a GroupedTimingStatistics object will be output.
 boolean isPrintNonStatistics()
          Gets the value of the PrintNonStatistics option.
 void setColumns(String columns)
          Sets the value of the Columns option.
 void setPivot(boolean pivot)
          Sets the value of the Pivot option.
 void setPrintNonStatistics(boolean printNonStatistics)
          Sets the value of the PrintNonStatistics option.
 
Methods inherited from class org.apache.log4j.Layout
getContentType, getFooter, getHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

csvFormatter

protected GroupedTimingStatisticsCsvFormatter csvFormatter
The csvFormatter is created in the activateOptions() method. The work of actually formatting the GroupedTimingStatistics object is delegated to this object.

Constructor Detail

StatisticsCsvLayout

public StatisticsCsvLayout()
Method Detail

isPivot

public boolean isPivot()
The Pivot option, which is false by default, determines whether or not a single line will be output for each GroupedTimingStatistics object, or whether one line for each tag within a GroupedTimingStatistics object will be output.

Returns:
the Pivot option.

setPivot

public void setPivot(boolean pivot)
Sets the value of the Pivot option.

Parameters:
pivot - The new Pivot option value.

getColumns

public String getColumns()
The Columns option is a comma-separated list of the values that should be output for each line that is printed. See the class javadoc for the allowed value.

Returns:
the Columns option.

setColumns

public void setColumns(String columns)
Sets the value of the Columns option.

Parameters:
columns - The new Columns option value.

isPrintNonStatistics

public boolean isPrintNonStatistics()
Gets the value of the PrintNonStatistics option. In general, this layout should only be used for appenders that deal with GroupedTimingStatistics objects (e.g. a FileAppender attached to an AsyncCoalescingStatisticsAppender). By default, any logging event where the message is NOT a GroupedTimingStatistics object is not output. However, if this option is set to true, then non-GroupedTimingStatistics messages will be output as their string value.

Returns:
the PrintNonStatistics option

setPrintNonStatistics

public void setPrintNonStatistics(boolean printNonStatistics)
Sets the value of the PrintNonStatistics option.

Parameters:
printNonStatistics - The new PrintNonStatistics option value.

format

public String format(LoggingEvent event)
Specified by:
format in class Layout

ignoresThrowable

public boolean ignoresThrowable()
This layout ignores Throwables set on the LoggingEvent.

Specified by:
ignoresThrowable in class Layout
Returns:
true

activateOptions

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


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