com.jamonapi.log4j
Class JAMonAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by com.jamonapi.log4j.JAMonAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public class JAMonAppender
extends org.apache.log4j.AppenderSkeleton

Title: JAMonAppender

Description: log4j Appender to that allows you to summarize log4j stats via jamon and view the tail of the log in realtime in a jamon web page. Click here for more info on how to use the JAMonAppender.

Copyright: Copyright (c) 2007

Author:
Ed Desrosiers, Steve Souza

Field Summary
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
JAMonAppender()
           
 
Method Summary
protected  void append(org.apache.log4j.spi.LoggingEvent event)
          If the appender is enabled then start and stop a JAMon entry.
 void close()
          Required log4j method.
 boolean getEnableLevelMonitoring()
          Returns whether or not LevelMonitoring is enabled or not.
 boolean getEnableListenerDetails()
          Specifies whether or not LoggingEvent info will be used in the attached Log4jBufferListener.
 boolean getGeneralize()
          Return whether or not generalization will occur
 java.lang.String getUnits()
           
 boolean hasGeneralizer()
          Indicates whether or not a Generalizer has been set
 boolean requiresLayout()
           JAMonAppender doesn't have to have a layount because it is acceptable to default to using the raw message.
 void setEnableDefaultGeneralizer(boolean enableDefaultGeneralizer)
          Enable the use of the DefaultGeneralizer.
 void setEnableLevelMonitoring(boolean enableLevelMonitoring)
          Specifies whether or not there will be a JAMon record for each log4j Level (DEBUG/WARN/...), and another one that corresponds to all calls to log4j logging methods.
 void setEnableListenerDetails(boolean arrayDetails)
          Specify whether or not LoggingEvent info will be used in the attached Log4jBufferListener
 void setEnableListeners(java.lang.String level)
          Note this is primarily used by the log4j configurator.
 void setGeneralize(boolean generalize)
          Indicate whether or not a jamon record should be created from the passed in message.
 void setGeneralizerClass(Generalizer generalizer)
          Default generalizer based on com.jamonapi.utils.SQLDeArger.
 void setGeneralizerDynamic(java.lang.String generalizerClassStr)
          Pass in a string class name and this generalizer will be constructed an used.
 void setListenerBufferSize(int bufferSize)
          For defaultBufferSize to take hold it must be called before the first call to setDefaultListeners.
 void setUnits(java.lang.String units)
           
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
activateOptions, 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

JAMonAppender

public JAMonAppender()
Method Detail

append

protected void append(org.apache.log4j.spi.LoggingEvent event)
If the appender is enabled then start and stop a JAMon entry. Depending on how this object is configured it may also put details into a JAMonBufferLister and generalize the logging message (logger.error(message) etc) and put it in jamon too. By default it will only do jamon records for each of the log4j Levels.

Specified by:
append in class org.apache.log4j.AppenderSkeleton
Parameters:
event -

close

public void close()
Required log4j method. Currently a no-op.

Specified by:
close in interface org.apache.log4j.Appender
Specified by:
close in class org.apache.log4j.AppenderSkeleton

requiresLayout

public boolean requiresLayout()

JAMonAppender doesn't have to have a layount because it is acceptable to default to using the raw message. Not providing a layout will return a log4j error that looks like the following, however it can safely be ignored. Providing any layout for the JAMonAppender will make the error go away. Unfortunately log4j doesn't have a way to specify an optional layout.

log4j:ERROR Could not find value for key log4j.appender.jamonAppender.layout

Specified by:
requiresLayout in interface org.apache.log4j.Appender
Specified by:
requiresLayout in class org.apache.log4j.AppenderSkeleton

getUnits

public java.lang.String getUnits()
Returns:
Returns the units. By default this is 'log4j' though it can be changed. This is used as part of the jamon key.

setUnits

public void setUnits(java.lang.String units)
Parameters:
units - The units to set.

getEnableListenerDetails

public boolean getEnableListenerDetails()
Specifies whether or not LoggingEvent info will be used in the attached Log4jBufferListener. By default this is enabled.


setEnableListenerDetails

public void setEnableListenerDetails(boolean arrayDetails)
Specify whether or not LoggingEvent info will be used in the attached Log4jBufferListener


setEnableLevelMonitoring

public void setEnableLevelMonitoring(boolean enableLevelMonitoring)
Specifies whether or not there will be a JAMon record for each log4j Level (DEBUG/WARN/...), and another one that corresponds to all calls to log4j logging methods. It is identified by the label TOTAL. By default this is enabled.


getEnableLevelMonitoring

public boolean getEnableLevelMonitoring()
Returns whether or not LevelMonitoring is enabled or not.


setEnableListeners

public void setEnableListeners(java.lang.String level)
Note this is primarily used by the log4j configurator. Valid values are the various log4j levels: DEBUG/ERROR/WARN/INFO/ERROR/FATAL, as well as TOTAL (A listener that gets called for all levels), BASIC (same as calling TOTAL/ERROR/FATAL), and ALL (same as calling ERROR/WARN/INFO/ERROR/FATAL/TOTAL). Values are not case sensitive. .

Parameters:
level -

setListenerBufferSize

public void setListenerBufferSize(int bufferSize)
For defaultBufferSize to take hold it must be called before the first call to setDefaultListeners. By default the buffer size is 100.

Parameters:
bufferSize -

setGeneralize

public void setGeneralize(boolean generalize)
Indicate whether or not a jamon record should be created from the passed in message. Note you can use the DefaultGeneralizer, your own Generalizer. It is very important that you ensure the String returned by the generalizer is unique enough that JAMon doesn't grow unbounded. For example by choosing to use no Generalizer you must pass in a relatively unique log4j string.

Parameters:
generalize -

getGeneralize

public boolean getGeneralize()
Return whether or not generalization will occur


setEnableDefaultGeneralizer

public void setEnableDefaultGeneralizer(boolean enableDefaultGeneralizer)
Enable the use of the DefaultGeneralizer. As a side effect setGeneralize(true) is called telling this class to generalize.

Parameters:
enableDefaultGeneralizer -

hasGeneralizer

public boolean hasGeneralizer()
Indicates whether or not a Generalizer has been set


setGeneralizerClass

public void setGeneralizerClass(Generalizer generalizer)
Default generalizer based on com.jamonapi.utils.SQLDeArger. It generalizes by replacing numbers and strings in single or double quotes with '?'. i.e. select * from table where name = 'steve' and id=50 becomes select * from table where name = ? and id=?. Developers can provide their own Generalizer if this is not the desired behaviour. Although the example uses a query the code works equally well with any String. The generalizer is used to create a record appropriate for jamon from a detail String that goes to log4j.


setGeneralizerDynamic

public void setGeneralizerDynamic(java.lang.String generalizerClassStr)
                           throws java.lang.InstantiationException,
                                  java.lang.IllegalAccessException,
                                  java.lang.ClassNotFoundException
Pass in a string class name and this generalizer will be constructed an used. For example com.jamonapi.utils.DefaultGeneralizer could be passed in

Parameters:
generalizerClassStr -
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException