Package org.perf4j.log4j

Provides the log4j appenders that can be used to automatically aggregate and analyze StopWatch timing statements logged to a org.apache.log4j.Logger.

See:
          Description

Class Summary
AsyncCoalescingStatisticsAppender This log4j Appender groups StopWatch log messages together to form GroupedTimingStatistics.
GraphingStatisticsAppender This appender is designed to be attached to an AsyncCoalescingStatisticsAppender.
JmxAttributeStatisticsAppender This appender is designed to be attached to an AsyncCoalescingStatisticsAppender.
 

Package org.perf4j.log4j Description

Provides the log4j appenders that can be used to automatically aggregate and analyze StopWatch timing statements logged to a org.apache.log4j.Logger. Three appenders are provided:

  1. AsyncCoalescingStatisticsAppender - This appender is used to group logged StopWatch messages over a specified time span (defaults to 30 seconds) into single GroupedTimingStatistics messages. Other appenders are designed to be attached to this appender, and these downstream appenders are then only notified of this single GroupedTimingStatistics message at the specified interval. Note that this appender cannot be configured with a log4j.properties file but must instead be configured with a log4j.xml file (if auto-configuration is used in your application).
  2. JmxAttributeStatisticsAppender - This appender, when attached to an AsyncCoalescingStatisticsAppender described above, can be used to expose timing statistics (such as mean, min and max values) as attributes on a JMX MBean. Since there are many 3rd party tools designed to interact through JMX, this provides a way to allow monitoring and notification when application runtime performance degrades.
  3. GraphingStatisticsAppender - This appender is used to output graphs (as a URL to the graph object) backed by the logged GroupedTimingStatistics instances (thus, it is also designed to be attached to an AsyncCoalescingStatisticsAppender). In addition, these graphs can be made available through a web server using a GraphingServlet instance in concert with this class.
The following example shows how logging could be configured using a log4j.xml file:
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

 <log4j:configuration debug="false" xmlns:log4j="http://jakarta.apache.org/log4j/">
   <!-- Main file output appender -->
   <appender name="rolling" class="org.apache.log4j.DailyRollingFileAppender">
     <param name="File" value="./logs/application.log"/>
     <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%-5p[%d{yyyy-MM-dd HH:mm:ss}][%-24t] : %m%n"/>
     </layout>
   </appender>

   <!-- Perf4J appenders -->
   <!-- CoalescingStatistics appender used to group StopWatch logs into GroupedTimingStatistics logs -->
   <appender name="CoalescingStatistics" class="org.perf4j.log4j.AsyncCoalescingStatisticsAppender">
     <param name="TimeSlice" value="10000"/> <!-- 10 second time slice -->
     <!-- The appenders defined below are attached here -->
     <appender-ref ref="Perf4jJMX"/>
     <appender-ref ref="PageTimes"/>
     <appender-ref ref="PageTPS"/>
   </appender>

   <!-- This appender exposes the timing statistics as an MBean through the default platform MBean server -->
   <appender name="Perf4jJMX" class="org.perf4j.log4j.JmxAttributeStatisticsAppender">
     <param name="TagNamesToExpose" value="operation1,dbcall,servicecall"/>
     <param name="MBeanName" value="org.perf4j.beans:type=Perf4J,name=ApplicationPerf"/>
   </appender>

   <!--
     This appender exposes mean execution times as a graph. You would most likely want to use
     a GraphingServlet (set up through a web.xml file) in addition to this appender
   -->
   <appender name="PageTimes" class="org.perf4j.log4j.GraphingStatisticsAppender">
     <param name="GraphType" value="Mean"/>
     <param name="TagNamesToGraph" value="operation1,dbcall,servicecall"/>
   </appender>

   <!--
     This appender exposes transactions per second values as a graph, and would also most likely be used
     with a GraphingServlet.
   -->
   <appender name="PageTPS" class="org.perf4j.log4j.GraphingStatisticsAppender">
     <param name="GraphType" value="TPS"/>
     <param name="TagNamesToGraph" value="search,propDetails,landingPage,propertyCounts"/>
   </appender>

   <!-- Loggers -->
   <!-- Perf4J logger -->
   <logger name="org.perf4j.TimingLogger" additivity="false">
     <level value="info"/>
     <appender-ref ref="CoalescingStatistics"/>
     <appender-ref ref="rolling"/>
   </logger>

   <root>
     <level value="ERROR"/>
     <appender-ref ref="rolling"/>
   </root>
 </log4j:configuration>
 



Copyright © 2008 perf4j.org. All Rights Reserved.