Log4j 1.1.3

org.apache.log4j.examples.appserver
Class AppServerCategory

java.lang.Object
  |
  +--org.apache.log4j.Category
        |
        +--org.apache.log4j.examples.appserver.AppServerCategory
All Implemented Interfaces:
AppenderAttachable

public class AppServerCategory
extends Category

Extends Category by adding four text attributes relevant to applications applications run in application servers. These attributes are

This Category subclass generates AppServerLoggingEvent subclasses of LoggingEvent which include the additional attributes. AppServerPatternLayout provides the ability to format these attributes.

Rather than set all these attributes for each AppServerCategory instance, it is usually more convenient to set them once on AppServerCategoryFactory. The factory can then be associated with the AppServerCategory class via setFactory(org.apache.log4j.spi.CategoryFactory) or with the entire hierarchy via Hierarchy.setCategoryFactory(org.apache.log4j.spi.CategoryFactory). In the former case, you should use getInstance(java.lang.String) to create new categories. In the latter case, you would use Category.getInstance(String). The former method allows finer granularity of control; the latter is more convenient. Reliance on the PropertyConfigurator will employ the latter.

More convenient still is to rely on the Category static initializer. See the package level documention for details.

Author:
Paul Glezen

Field Summary
protected  String component
          The name of the component using this category.
protected  String hostname
          The hostname on which this category resides.
protected  String server
          The application server name for this category.
protected  String version
          An identifier for this particular version/release.
 
Fields inherited from class org.apache.log4j.Category
additive, DEFAULT_CONFIGURATION_FILE, DEFAULT_CONFIGURATION_KEY, DEFAULT_INIT_OVERRIDE_KEY, defaultHierarchy, hierarchy, name, parent, priority, resourceBundle
 
Constructor Summary
protected AppServerCategory(String categoryName, String hostname, String server, String component, String version)
          Construct a new AppServerCategory with the provided attributes.
 
Method Summary
protected  void forcedLog(String fqn, Priority priority, Object message, Throwable t)
          This method is overridden to ensure an instance of AppServerLoggingEvent is sent to the appenders.
 String getComponent()
          Get the component name for this category.
 String getHostname()
          Get the hostname for this category.
static Category getInstance(String name)
          Return an AppServerCategory instance with the provided name.
 String getServer()
          Get the server name for this category.
 String getVersion()
          Get the version name for this category.
 void setComponent(String componentName)
          Set the component name for this category.
static void setFactory(CategoryFactory factory)
          Set the factory instance for creation of AppServerCategory instances. in the getInstance method.
 void setHostname(String hostname)
          Explicity set the hostname for this category.
 void setServer(String serverName)
          Set the server name for this category.
 void setVersion(String versionName)
          Set the version of the component for this category.
 
Methods inherited from class org.apache.log4j.Category
addAppender, assert, callAppenders, debug, debug, error, error, exists, fatal, fatal, getAdditivity, getAllAppenders, getAppender, getChainedPriority, getCurrentCategories, getDefaultHierarchy, getHierarchy, getInstance, getInstance, getName, getPriority, getResourceBundle, getResourceBundleString, getRoot, info, info, isDebugEnabled, isEnabledFor, isInfoEnabled, l7dlog, l7dlog, log, log, log, removeAllAppenders, removeAppender, removeAppender, setAdditivity, 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

component

protected String component
The name of the component using this category.

hostname

protected String hostname
The hostname on which this category resides.

server

protected String server
The application server name for this category. This is particularly meaningful in a CORBA or EBJ application server environment.

version

protected String version
An identifier for this particular version/release.
Constructor Detail

AppServerCategory

protected AppServerCategory(String categoryName,
                            String hostname,
                            String server,
                            String component,
                            String version)
Construct a new AppServerCategory with the provided attributes. The constructor is protected because the only classes invoking it should be a CategoryFactory subclass or a subclass of AppServerCategory.
Parameters:
categoryName - the name of the category.
instanceFCQN - the fully qualified name of this category instance
hostname - the name of the physical machine on which this category resides. This may be null.
server - the name of the server using this category. This may be null.
component - the name of the component using this category. This may be null.
version - the version identifier of the component. This may may be null.
Method Detail

getComponent

public String getComponent()
Get the component name for this category.
Returns:
the category name

getHostname

public String getHostname()
Get the hostname for this category.
Returns:
a string representation of the hostname

getInstance

public static Category getInstance(String name)
Return an AppServerCategory instance with the provided name. If such an instance exists, return it. Otherwise, create a new one.
Parameters:
name - the name of the Catgory
Returns:
an instance of AppServerCategory. The signature indicates Category to maintain compatibility with the base class.

getServer

public String getServer()
Get the server name for this category. This attribute is more germane in application server environments such as CORBA and EJB.
Returns:
a string representing the server name

getVersion

public String getVersion()
Get the version name for this category.
Returns:
the version of the the component for this category.

forcedLog

protected void forcedLog(String fqn,
                         Priority priority,
                         Object message,
                         Throwable t)
This method is overridden to ensure an instance of AppServerLoggingEvent is sent to the appenders.
Overrides:
forcedLog in class Category

setComponent

public void setComponent(String componentName)
Set the component name for this category.
Parameters:
categoryName - the component name to be used for this category.

setFactory

public static void setFactory(CategoryFactory factory)
Set the factory instance for creation of AppServerCategory instances. in the getInstance method.
Parameters:
factory - an AppServerCategory factory

setHostname

public void setHostname(String hostname)
Explicity set the hostname for this category.
Parameters:
hostname - the hostname to be used for this category.

setServer

public void setServer(String serverName)
Set the server name for this category.
Parameters:
serverName - the server name to be used for this category. This is useful in CORBA and EJB environments.

setVersion

public void setVersion(String versionName)
Set the version of the component for this category.
Parameters:
versionName - version name

Log4j 1.1.3

Please notify me about new log4j releases.