OpenNMS API 1.2.3

org.opennms.core.utils
Class ThreadCategory

java.lang.Object
  extended byorg.apache.log4j.Category
      extended byorg.opennms.core.utils.ThreadCategory
All Implemented Interfaces:
org.apache.log4j.spi.AppenderAttachable

public class ThreadCategory
extends org.apache.log4j.Category

This class is designed to work with log4j based on threads and not class names. This allows all the classes invoked by a thread to log their messages to the same location. This is particularly useful when messages from share common code should be associated with a higher level service or application.

Author:
Brian Weaver , OpenNMS

Field Summary
private static java.lang.InheritableThreadLocal m_tgCategory
          This thread local variable is used to store the category that threads (and their children) should use to log information.
 
Fields inherited from class org.apache.log4j.Category
additive, level, name, parent, repository, resourceBundle
 
Constructor Summary
protected ThreadCategory(java.lang.String name)
          This constructor created a new Category instance and sets its name.
 
Method Summary
static org.apache.log4j.Category getInstance()
          This method is used to get the category instance associated with the thread.
static org.apache.log4j.Category getInstance(java.lang.Class c)
          This method is used to get the category instance associated with the thread.
static org.apache.log4j.Category getInstance(java.lang.String cname)
          This method is used to get the category instance associated with the thread.
static java.lang.String getPrefix()
          This is used to retreive the current prefix as it has been inhereited by the calling thread.
static void setPrefix(java.lang.String prefix)
          This method is used to set a prefix for the category name that is used for all category instances in this thread.
 
Methods inherited from class org.apache.log4j.Category
addAppender, assertLog, callAppenders, debug, debug, error, error, exists, fatal, fatal, forcedLog, getAdditivity, getAllAppenders, getAppender, getChainedPriority, getCurrentCategories, getDefaultHierarchy, getEffectiveLevel, getHierarchy, getLevel, getLoggerRepository, getName, getParent, getPriority, getResourceBundle, getResourceBundleString, getRoot, info, info, isAttached, isDebugEnabled, isEnabledFor, isInfoEnabled, l7dlog, l7dlog, log, log, log, removeAllAppenders, removeAppender, removeAppender, setAdditivity, setLevel, setPriority, setResourceBundle, shutdown, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_tgCategory

private static java.lang.InheritableThreadLocal m_tgCategory
This thread local variable is used to store the category that threads (and their children) should use to log information. If a thread has a set category and then starts a new thread, the new thread will inherit the category of the parent thread.

Constructor Detail

ThreadCategory

protected ThreadCategory(java.lang.String name)
This constructor created a new Category instance and sets its name. It is intended to be used by sub-classes only. You should not create categories directly.

Parameters:
name - The name of the category
Method Detail

getInstance

public static org.apache.log4j.Category getInstance(java.lang.Class c)
This method is used to get the category instance associated with the thread. If the category for the thread has not been set then the passed class is used to find the appropriate category. If a category is found for the thread group then it is returned to the caller.

Parameters:
c - The class used to find the category if it was not set.
Returns:
The instance for the thread.
See Also:
InheritableThreadLocal

getInstance

public static org.apache.log4j.Category getInstance(java.lang.String cname)
This method is used to get the category instance associated with the thread. If the category for the thread has not been set then the passed name is used to find the appropriate category. If a category is found for the thread group then it is returned to the caller.

Parameters:
cname - The name used to find the category if it was not set.
Returns:
The instance for the thread.
See Also:
InheritableThreadLocal

getInstance

public static org.apache.log4j.Category getInstance()
This method is used to get the category instance associated with the thread. If the instance has not been set then a null is returned to the caller.

Returns:
The instance for the thread, null if it is not set.
See Also:
InheritableThreadLocal

setPrefix

public static void setPrefix(java.lang.String prefix)
This method is used to set a prefix for the category name that is used for all category instances in this thread. This is used to insure that all messages from a particular thread end up in the same log file, regardless of the package or class name of the class that generated the log message. Please restrict the usage of this function to only the highest level threads.


getPrefix

public static java.lang.String getPrefix()
This is used to retreive the current prefix as it has been inhereited by the calling thread. This is needed by many dyanmic threading classes like the RunnableConsumerThreadPool to ensure that all the internal threads run in the same category.

Returns:
The prefix string as inherieted by the calling thread.

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.