You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2001/01/24 11:24:12 UTC
cvs commit: jakarta-log4j/org/apache/log4j/xml/examples XCategory.java
ceki 01/01/24 02:24:12
Modified: doc HISTORY deepExtension.html
org/apache/log4j Category.java DefaultCategoryFactory.java
org/apache/log4j/examples Makefile MyCategory.java
MyCategoryFactory.java
org/apache/log4j/examples/appserver AppServerCategory.java
AppServerCategoryFactory.java
org/apache/log4j/spi RootCategory.java
org/apache/log4j/xml/examples XCategory.java
Log:
- Made the instanceFCQN an instance variable instead of a class static in Category.java.
In related move, the Category constructor now takes an additional argument setting the
instanceFCQN. This makes life less miserable for Category subclasses. [*]
- Updated the "Adding Conversion Characters to PatternLayout" document to reflect the
latest changes to the code. Also added the org/apache/log4j/examples/appserver
directory containing the associated example code. [*]
Revision Changes Path
1.10 +4 -0 jakarta-log4j/doc/HISTORY
Index: HISTORY
===================================================================
RCS file: /home/cvs/jakarta-log4j/doc/HISTORY,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HISTORY 2001/01/23 22:07:24 1.9
+++ HISTORY 2001/01/24 10:24:02 1.10
@@ -36,6 +36,10 @@
the static initializer of Category class. Thanks to Calvin Chan for
supplying a better method. [*]
+ - Updated the "Adding Conversion Characters to PatternLayout" document to reflect the
+ latest changes to the code. Also added the org/apache/log4j/examples/appserver
+ directory containing the associated example code. [*]
+
- Added the BufferSize option to the AsyncAppender. [*]
- Eliminateed the SecurityExceptions thrown in Applets. Thanks Timur
1.5 +26 -5 jakarta-log4j/doc/deepExtension.html
Index: deepExtension.html
===================================================================
RCS file: /home/cvs/jakarta-log4j/doc/deepExtension.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- deepExtension.html 2001/01/23 22:07:25 1.4
+++ deepExtension.html 2001/01/24 10:24:02 1.5
@@ -18,7 +18,7 @@
<p>
This article describes a systematic way to extend the
-<a href="http://log4j.org">log4j</a> API in order include
+<a href="http://jakarta.apache.org/log4j">log4j</a> API in order include
additional attributes that can be formatted using the
<code><a href="../javadoc/org/apache/log4j/PatternLayout.html">PatternLayout</a></code>
class.
@@ -54,7 +54,7 @@
This article assumes familiarity with the log4j
<a href="manual.html">User Manual</a>. It builds on fundamental
classes described in both the User Manual and the
-<a href="index.html">Javadoc</a>. To assist in illustrating the
+<a href="../javadoc/index.html">Javadoc</a>. To assist in illustrating the
concepts, a simple case study will be developed along side the
explanations. The resulting classes may be used as a template
for your own extensions. Condenced (i.e. statements compressed,
@@ -230,7 +230,7 @@
public AppServerLoggingEvent( String fqnOfCategoryClass,
AppServerCategory category,
Priority priority,
- String message,
+ Object message,
Throwable throwable)
{
super( fqnOfCategoryClass,
@@ -472,6 +472,9 @@
<code>AppServerLoggingEvent</code> is instantiated rather than
the default <code>LoggingEvent</code>.
<p>
+<li>Override the <code>l7dlog</code> methods since by default they
+ do not call the <code>forcedLog</code> method.
+<p>
<li>Override the <code>getInstance</code> method to use our
<code>CategoryFactory</code> (described in the next step). This will
require that we hold a static reference to our factory and provide a
@@ -526,6 +529,7 @@
String version )
{
super( categoryName );
+ <b>instanceFQN = "org.apache.log4j.examples.appserver.AppServerCategory";</b>
this.hostname = hostname;
this.server = server;
@@ -612,6 +616,7 @@
protected String server;
protected String component;
protected String version;
+ protected ResourceBundle messageBundle;
protected AppServerCategoryFactory( String serverName,
String componentName,
@@ -637,12 +642,23 @@
*/
public Category makeNewCategoryInstance(String name)
{
- return new AppServerCategory(name, hostname, server, component, version);
+ Category result = new AppServerCategory(name, hostname, server, component, version);
+ if ( messageBundle != null )
+ result.setResourceBundle( messageBundle );
+ return result;
}
+
+ public void setMessageBundle(ResourceBundle bundle)
+ { messageBundle = bundle; }
}
</pre>
</table>
<p>
+Notice that we have also added the ability to set the message catalog
+<code>ResourceBundle</code> on the factory so that all subsequent
+<code>Category</code> creations will have it set automatically for use
+with the <code>l7dlog</code> methods.
+<p>
<hr>
<a name="usage"><h2>Usage</h2></a>
We now arrive at how to use what we have created. We must remember to
@@ -721,7 +737,12 @@
similar to that of class and category names whereby only a certain
number of the more significant components are displayed. But
whereas with class and category names, the most significant component
- is on the right, with host names, it is on the right.
+ is on the right, with host names, it is on the left.
+<p>
+<li>Allow one to set a ResourceBundle on a factory so that categories
+ are created with the message bundle already set (in preparation
+ for using the <code>l7dlog</code> methods).
+<p>
<li>Specifying a version number could be dangerous since programmers
are apt to change versions of the code without changing the
string constant in the code which specifies the version. Some
1.19 +36 -31 jakarta-log4j/org/apache/log4j/Category.java
Index: Category.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/Category.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Category.java 2001/01/22 22:11:25 1.18
+++ Category.java 2001/01/24 10:24:04 1.19
@@ -51,10 +51,6 @@
@author Anders Kristensen */
public class Category implements AppenderAttachable {
- private static String DEFAULT_FQN = "org.apache.log4j.Category";
-
- protected static String instanceFQN;
-
/**
The hierarchy where categories are attached to by default.
*/
@@ -63,11 +59,6 @@
final Hierarchy defaultHierarchy = new Hierarchy(new
RootCategory(Priority.DEBUG));
-
- protected ResourceBundle resourceBundle;
-
- // Categories need to know what Hierarchy they are in
- protected Hierarchy hierarchy;
/**
This string constant is set to <b>log4j.properties</b> the name
@@ -166,6 +157,17 @@
ancestor which is the root category. */
protected Category parent;
+ /**
+ The fully qualified name of the class that this Category
+ object. Subclasses should override this variable. */
+ public final String instanceFQCN;
+
+ protected ResourceBundle resourceBundle;
+
+ // Categories need to know what Hierarchy they are in
+ protected Hierarchy hierarchy;
+
+
AppenderAttachableImpl aai;
/** Additivity is set to true by default, that is children inherit
@@ -184,11 +186,14 @@
<p>It is intended to be used by sub-classes only. You should not
create categories directly.
- @param name The name of the category. */
+ @param name The name of the category.
+ @param instanceFQCN The fully qualified name of the class that this
+ category instance belongs to. Subclasses of Category
+ must specify their own fully qualified class name. */
protected
- Category(String name) {
+ Category(String name, String instanceFQCN) {
this.name = name;
- this.instanceFQN = DEFAULT_FQN;
+ this.instanceFQCN = instanceFQCN;
}
/**
@@ -298,7 +303,7 @@
if(hierarchy.disable >= Priority.DEBUG_INT)
return;
if(Priority.DEBUG.isGreaterOrEqual(this.getChainedPriority())) {
- forcedLog(instanceFQN, Priority.DEBUG, message, null);
+ forcedLog(instanceFQCN, Priority.DEBUG, message, null);
}
}
@@ -316,7 +321,7 @@
void debug(Object message, Throwable t) {
if(hierarchy.disable >= Priority.DEBUG_INT) return;
if(this.isEnabledFor(Priority.DEBUG))
- forcedLog(instanceFQN, Priority.DEBUG, message, t);
+ forcedLog(instanceFQCN, Priority.DEBUG, message, t);
}
@@ -351,7 +356,7 @@
void error(Object message) {
if(hierarchy.disable >= Priority.ERROR_INT) return;
if(this.isEnabledFor(Priority.ERROR))
- forcedLog(instanceFQN, Priority.ERROR, message, null);
+ forcedLog(instanceFQCN, Priority.ERROR, message, null);
}
/**
@@ -367,7 +372,7 @@
void error(Object message, Throwable t) {
if(hierarchy.disable >= Priority.ERROR_INT) return;
if(this.isEnabledFor(Priority.ERROR))
- forcedLog(instanceFQN, Priority.ERROR, message, t);
+ forcedLog(instanceFQCN, Priority.ERROR, message, t);
}
@@ -407,7 +412,7 @@
void fatal(Object message) {
if(hierarchy.disable >= Priority.FATAL_INT) return;
if(Priority.FATAL.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, Priority.FATAL, message, null);
+ forcedLog(instanceFQCN, Priority.FATAL, message, null);
}
/**
@@ -423,7 +428,7 @@
void fatal(Object message, Throwable t) {
if(hierarchy.disable >= Priority.FATAL_INT) return;
if(Priority.FATAL.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, Priority.FATAL, message, t);
+ forcedLog(instanceFQCN, Priority.FATAL, message, t);
}
@@ -431,8 +436,8 @@
This method creates a new logging event and logs the event
without further checks. */
protected
- void forcedLog(String fqn, Priority priority, Object message, Throwable t) {
- callAppenders(new LoggingEvent(fqn, this, priority, message, t));
+ void forcedLog(String FQCN, Priority priority, Object message, Throwable t) {
+ callAppenders(new LoggingEvent(FQCN, this, priority, message, t));
}
@@ -682,7 +687,7 @@
void info(Object message) {
if(hierarchy.disable >= Priority.INFO_INT) return;
if(Priority.INFO.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, Priority.INFO, message, null);
+ forcedLog(instanceFQCN, Priority.INFO, message, null);
}
/**
@@ -698,7 +703,7 @@
void info(Object message, Throwable t) {
if(hierarchy.disable >= Priority.INFO_INT) return;
if(Priority.INFO.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, Priority.INFO, message, t);
+ forcedLog(instanceFQCN, Priority.INFO, message, t);
}
/**
@@ -794,7 +799,7 @@
if(msg == null) {
msg = key;
}
- callAppenders(new LoggingEvent(instanceFQN, this, priority, msg, t));
+ forcedLog(instanceFQCN, priority, msg, t);
}
}
/**
@@ -818,7 +823,7 @@
msg = key;
else
msg = java.text.MessageFormat.format(pattern, params);
- callAppenders(new LoggingEvent(instanceFQN, this, priority, msg, t));
+ forcedLog(instanceFQCN, priority, msg, t);
}
}
@@ -831,7 +836,7 @@
return;
}
if(priority.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, priority, message, t);
+ forcedLog(instanceFQCN, priority, message, t);
}
/**
@@ -843,7 +848,7 @@
return;
}
if(priority.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, priority, message, null);
+ forcedLog(instanceFQCN, priority, message, null);
}
/**
@@ -851,18 +856,18 @@
This is the most generic printing method. It is intended to be
invoked by wrapper classes.
- @param callerFQN The wrapper class' fully qualified class name.
+ @param callerFQCN The wrapper class' fully qualified class name.
@param priority The priority of the logging request.
@param message The message of the logging request.
@param t The throwable of the logging request, may be null.
*/
public
- void log(String callerFQN, Priority priority, Object message, Throwable t) {
+ void log(String callerFQCN, Priority priority, Object message, Throwable t) {
if(hierarchy.disable >= priority.level) {
return;
}
if(priority.isGreaterOrEqual(this.getChainedPriority())) {
- forcedLog(callerFQN, priority, message, t);
+ forcedLog(callerFQCN, priority, message, t);
}
}
@@ -992,7 +997,7 @@
public
void warn(Object message) {
if(this.isEnabledFor(Priority.WARN))
- forcedLog(instanceFQN, Priority.WARN, message, null);
+ forcedLog(instanceFQCN, Priority.WARN, message, null);
}
/**
@@ -1007,6 +1012,6 @@
public
void warn(Object message, Throwable t) {
if(this.isEnabledFor(Priority.WARN))
- forcedLog(instanceFQN, Priority.WARN, message, t);
+ forcedLog(instanceFQCN, Priority.WARN, message, t);
}
}
1.3 +3 -1 jakarta-log4j/org/apache/log4j/DefaultCategoryFactory.java
Index: DefaultCategoryFactory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/DefaultCategoryFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultCategoryFactory.java 2000/12/14 21:07:17 1.2
+++ DefaultCategoryFactory.java 2001/01/24 10:24:05 1.3
@@ -11,11 +11,13 @@
class DefaultCategoryFactory implements CategoryFactory {
+ private static final String DEFAULT_FQN = "org.apache.log4j.Category";
+
DefaultCategoryFactory() {
}
public
Category makeNewCategoryInstance(String name) {
- return new Category(name);
+ return new Category(name, DEFAULT_FQN);
}
}
1.3 +1 -1 jakarta-log4j/org/apache/log4j/examples/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/examples/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Makefile 2000/12/14 21:07:33 1.2
+++ Makefile 2001/01/24 10:24:06 1.3
@@ -12,7 +12,7 @@
JRMI:=NumberCruncherServer.java
-SUBDIRS :=
+SUBDIRS :=appserver
# include master-rule file
include $(DEPTH)/make/make.inc
1.3 +2 -2 jakarta-log4j/org/apache/log4j/examples/MyCategory.java
Index: MyCategory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/examples/MyCategory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MyCategory.java 2000/12/14 21:07:33 1.2
+++ MyCategory.java 2001/01/24 10:24:06 1.3
@@ -80,8 +80,8 @@
/**
Just calls the parent constuctor.
*/
- public MyCategory(String name) {
- super(name);
+ public MyCategory(String name, String instanceFQCN) {
+ super(name, instanceFQCN);
}
1.3 +4 -1 jakarta-log4j/org/apache/log4j/examples/MyCategoryFactory.java
Index: MyCategoryFactory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/examples/MyCategoryFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MyCategoryFactory.java 2000/12/14 21:07:34 1.2
+++ MyCategoryFactory.java 2001/01/24 10:24:06 1.3
@@ -18,6 +18,9 @@
@author Ceki Gülcü */
public class MyCategoryFactory implements CategoryFactory {
+
+ private static String FQCN = MyCategory.class.getName();
+
/**
The constructor should be public as it will be called by
configurators in different packages. */
@@ -27,6 +30,6 @@
public
Category makeNewCategoryInstance(String name) {
- return new MyCategory(name);
+ return new MyCategory(name, FQCN);
}
}
1.3 +4 -67 jakarta-log4j/org/apache/log4j/examples/appserver/AppServerCategory.java
Index: AppServerCategory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/examples/appserver/AppServerCategory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AppServerCategory.java 2001/01/23 23:47:10 1.2
+++ AppServerCategory.java 2001/01/24 10:24:08 1.3
@@ -70,6 +70,7 @@
* a subclass of AppServerCategory.
*
* @param categoryName the name of the category.
+ * @param instanceFCQN the fully qualified name of this category instance
* @param hostname the name of the physical machine on which this
* category resides. This may be null.
* @param server the name of the server using this category. This
@@ -79,13 +80,9 @@
* @param version the version identifier of the component. This may
* may be null.
*/
- protected AppServerCategory( String categoryName,
- String hostname,
- String server,
- String component,
- String version ) {
- super( categoryName );
- instanceFQN = "org.apache.log4j.examples.appserver.AppServerCategory";
+ protected AppServerCategory( String categoryName, String instanceFCQN, String hostname,
+ String server, String component, String version ) {
+ super(categoryName, instanceFCQN);
this.hostname = hostname;
this.server = server;
@@ -174,66 +171,6 @@
callAppenders( event );
}
- /**
- * Log a message based on a key used to index into a message
- * catalog stored in a <code>java.util.ResourceBundle</code>.
- * This version of l7dlog assumes no substitutable parameters.
- * This class overrides its corresponding method in
- * <code>Category</code> so that an <code>AppServerLoggingEvent</code>
- * is created rather than a <code>LoggingEvent</code> instance.
- *
- * @param priority the priority at which to log this message
- * @param key used to index into a <code>ResourceBundle</code>
- * for retrieving a message.
- * @param t an exception instance from which to extract more
- * information.
- */
- public void l7dlog(Priority priority, String key, Throwable t) {
- if(hierarchy.isDisabled(priority.toInt()))
- return;
-
- if( priority.isGreaterOrEqual( getChainedPriority() ) ) {
- String msg = getResourceBundleString(key);
- // if message corresponding to 'key' could not be found in the
- // resource bundle, then default to 'key'.
- if(msg == null)
- msg = key;
-
- callAppenders(new AppServerLoggingEvent(instanceFQN, this, priority, msg, t));
- }
- }
-
- /**
- * Log a message based on a key used to index into a message
- * catalog stored in a <code>java.util.ResourceBundle</code>.
- * This version of l7dlog provides for substitutable parameters
- * in the form of an object array.
- * This class overrides its corresponding method in
- * <code>Category</code> so that an <code>AppServerLoggingEvent</code>
- * is created rather than a <code>LoggingEvent</code> instance.
- *
- * @param priority the priority at which to log this message
- * @param key used to index into a <code>ResourceBundle</code>
- * for retrieving a message.
- * @param params the substitutable parameters.
- * @param t an exception instance from which to extract more
- * information.
- */
- public void l7dlog(Priority priority, String key, Object[] params, Throwable t) {
- if(hierarchy.isDisabled(priority.toInt()))
- return;
-
- if(priority.isGreaterOrEqual(this.getChainedPriority())) {
- String pattern = getResourceBundleString(key);
- String msg;
- if(pattern == null)
- msg = key;
- else
- msg = java.text.MessageFormat.format(pattern, params);
-
- callAppenders(new AppServerLoggingEvent( instanceFQN, this, priority, msg, t));
- }
- }
/**
* Set the component name for this category.
1.2 +148 -161 jakarta-log4j/org/apache/log4j/examples/appserver/AppServerCategoryFactory.java
Index: AppServerCategoryFactory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/examples/appserver/AppServerCategoryFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AppServerCategoryFactory.java 2001/01/23 23:35:00 1.1
+++ AppServerCategoryFactory.java 2001/01/24 10:24:09 1.2
@@ -25,166 +25,153 @@
*
* @author Paul Glezen
*/
-public class AppServerCategoryFactory implements CategoryFactory
-{
- /** The hostname on which this factory resides. This is
- determined dynamically using the java.net.InetAddress
- class. */
- protected String hostname;
-
- /** The application server name for this factory. This
- is particularly meaningful in a CORBA or EBJ application
- server environment. */
- protected String server;
-
- /** The name of the component using this factory. */
- protected String component;
-
- /** An identifier for this particular version/release. */
- protected String version;
-
- /** The message bundle to be used by all categories. */
- protected ResourceBundle messageBundle;
-
- /**
- * Construct a new <code>AppServerCategoryFactory</code> with
- * the provided attributes. An attempt is made to obtain the
- * hostname from the java.net API.
- *
- * @param categoryName the name of the category.
- * @param serverName the name of the server using this category. This
- * may be null.
- * @param componentName the name of the component using this category.
- * This may be null.
- * @param versionName the version identifier of the component. This may
- * may be null.
- */
- public AppServerCategoryFactory( String serverName,
- String componentName,
- String versionName )
- {
- try
- {
- hostname = java.net.InetAddress.getLocalHost().getHostName();
- }
- catch ( java.net.UnknownHostException uhe )
- {
- System.err.println("AppServerCategoryFactory: could not determine local hostname.");
- }
-
- server = serverName;
- component = componentName;
- version = versionName;
- }
-
- /**
- * Get the name of the component for which this category is logging.
- *
- * @return the component name
- */
- public String getComponent()
- {
- return component;
- }
-
- /**
- * Get the hostname of the machine on which this category is running.
- *
- * @return the hostname
- */
- public String getHostname()
- {
- return hostname;
- }
-
- /**
- * Get the name of the server process in which this category is running.
- *
- * @return the server name
- */
- public String getServer()
- {
- return server;
- }
-
- /**
- * Get the version name of the component in which this category is
- * running.
- *
- * @return the version name
- */
- public String getVersion()
- {
- return version;
- }
-
- /**
- * Create a new instance of <code>AppServerCategory</code>
- * using the information contained in this instance.
- */
- public Category makeNewCategoryInstance(String name)
- {
- Category result = new AppServerCategory(name, hostname, server, component, version);
- if ( messageBundle != null )
- result.setResourceBundle( messageBundle );
-
- return result;
- }
-
- /**
- * Set the name of the component for which the category will be logging.
- *
- * @param component name of component
- *
- */
- public void setComponent(String component)
- {
- this.component = component;
- }
-
- /**
- * Set the host name of the component on which this category is running.
- * An attempt is made by the constructor to determine the hostname using
- * the java.net API. Use this method only to override this
- * determination.
- *
- * @param hostname the host name.
- */
- public void setHostname( String hostname )
- {
- this.hostname = hostname;
- }
-
- /**
- * Set the message bundle to be used for all <code>Category</code>
- * objects created by this <code>CatgoryFactory</code>.
- *
- * param bundle a bundle of messages
- */
- public void setMessageBundle(ResourceBundle bundle)
- {
- messageBundle = bundle;
- }
-
- /**
- * Set the name of the application server process in which this
- * category is logging.
- *
- * @param server name of application server process.
- */
- public void setServer(String server)
- {
- this.server = server;
- }
-
- /**
- * Set the version string for the component.
- *
- * @param version version name of component
- */
- public void setVersion(String version)
- {
- this.version = version;
- }
+public class AppServerCategoryFactory implements CategoryFactory {
+
+ private final String FCQN = AppServerCategory.class.getName();
+
+ /** The hostname on which this factory resides. This is
+ determined dynamically using the java.net.InetAddress
+ class. */
+ protected String hostname;
+
+ /** The application server name for this factory. This
+ is particularly meaningful in a CORBA or EBJ application
+ server environment. */
+ protected String server;
+
+ /** The name of the component using this factory. */
+ protected String component;
+
+ /** An identifier for this particular version/release. */
+ protected String version;
+
+ /** The message bundle to be used by all categories. */
+ protected ResourceBundle messageBundle;
+
+ /**
+ * Construct a new <code>AppServerCategoryFactory</code> with
+ * the provided attributes. An attempt is made to obtain the
+ * hostname from the java.net API.
+ *
+ * @param categoryName the name of the category.
+ * @param serverName the name of the server using this category. This
+ * may be null.
+ * @param componentName the name of the component using this category.
+ * This may be null.
+ * @param versionName the version identifier of the component. This may
+ * may be null.
+ */
+ public AppServerCategoryFactory( String serverName, String componentName,
+ String versionName ) {
+ try {
+ hostname = java.net.InetAddress.getLocalHost().getHostName();
+ } catch ( java.net.UnknownHostException uhe ) {
+ System.err.println("AppServerCategoryFactory: could not determine local hostname.");
+ }
+ server = serverName;
+ component = componentName;
+ version = versionName;
+ }
+
+ /**
+ * Get the name of the component for which this category is logging.
+ *
+ * @return the component name
+ */
+ public String getComponent() {
+ return component;
+ }
+
+ /**
+ * Get the hostname of the machine on which this category is running.
+ *
+ * @return the hostname
+ */
+ public String getHostname() {
+ return hostname;
+ }
+
+ /**
+ * Get the name of the server process in which this category is running.
+ *
+ * @return the server name
+ */
+ public String getServer() {
+ return server;
+ }
+
+ /**
+ * Get the version name of the component in which this category is
+ * running.
+ *
+ * @return the version name
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Create a new instance of <code>AppServerCategory</code>
+ * using the information contained in this instance.
+ */
+ public Category makeNewCategoryInstance(String name) {
+ Category result = new AppServerCategory(name, FCQN, hostname, server,
+ component, version);
+ if ( messageBundle != null )
+ result.setResourceBundle( messageBundle );
+
+ return result;
+ }
+
+ /**
+ * Set the name of the component for which the category will be logging.
+ *
+ * @param component name of component
+ *
+ */
+ public void setComponent(String component) {
+ this.component = component;
+ }
+
+ /**
+ * Set the host name of the component on which this category is running.
+ * An attempt is made by the constructor to determine the hostname using
+ * the java.net API. Use this method only to override this
+ * determination.
+ *
+ * @param hostname the host name.
+ */
+ public void setHostname( String hostname ) {
+ this.hostname = hostname;
+ }
+
+ /**
+ * Set the message bundle to be used for all <code>Category</code>
+ * objects created by this <code>CatgoryFactory</code>.
+ *
+ * param bundle a bundle of messages
+ */
+ public void setMessageBundle(ResourceBundle bundle) {
+ messageBundle = bundle;
+ }
+
+ /**
+ * Set the name of the application server process in which this
+ * category is logging.
+ *
+ * @param server name of application server process.
+ */
+ public void setServer(String server) {
+ this.server = server;
+ }
+
+ /**
+ * Set the version string for the component.
+ *
+ * @param version version name of component
+ */
+ public void setVersion(String version) {
+ this.version = version;
+ }
}
1.3 +2 -1 jakarta-log4j/org/apache/log4j/spi/RootCategory.java
Index: RootCategory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/spi/RootCategory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RootCategory.java 2000/12/14 21:08:11 1.2
+++ RootCategory.java 2001/01/24 10:24:10 1.3
@@ -26,6 +26,7 @@
*/
final public class RootCategory extends Category {
+ final private static String FQCN = RootCategory.class.getName();
/**
The root category names itself as "root". However, the root
@@ -33,7 +34,7 @@
*/
public
RootCategory(Priority priority) {
- super("root");
+ super("root", FQCN);
this.priority = priority;
}
1.7 +10 -10 jakarta-log4j/org/apache/log4j/xml/examples/XCategory.java
Index: XCategory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/xml/examples/XCategory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XCategory.java 2001/01/22 22:11:40 1.6
+++ XCategory.java 2001/01/24 10:24:11 1.7
@@ -36,9 +36,6 @@
// It's enough to instantiate a factory once and for all.
private static XFactory factory = new XFactory();
-
-
- static String instanceFQCN = XCategory.class.getName();
public static final String SUFFIX_OPTION = "Suffix";
@@ -47,8 +44,8 @@
/**
Just calls the parent constuctor.
*/
- public XCategory(String name) {
- super(name);
+ protected XCategory(String name, String instanceFQN) {
+ super(name, instanceFQN);
}
/**
@@ -64,7 +61,7 @@
*/
public
void debug(String message) {
- log(instanceFQCN, Priority.DEBUG, message + " " + suffix, null);
+ super.debug(message + " " + suffix);
}
/**
@@ -108,7 +105,7 @@
if(hierarchy.isDisabled(XPriority.LETHAL_INT))
return;
if(XPriority.LETHAL.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, XPriority.LETHAL, message, t);
+ forcedLog(instanceFQCN, XPriority.LETHAL, message, t);
}
/**
@@ -120,7 +117,7 @@
if(hierarchy.isDisabled(XPriority.LETHAL_INT))
return;
if(XPriority.LETHAL.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, XPriority.LETHAL, message, null);
+ forcedLog(instanceFQCN, XPriority.LETHAL, message, null);
}
@@ -150,7 +147,7 @@
if(hierarchy.isDisabled(XPriority.TRACE_INT))
return;
if(XPriority.TRACE.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, XPriority.TRACE, message, t);
+ forcedLog(instanceFQCN, XPriority.TRACE, message, t);
}
/**
@@ -171,12 +168,15 @@
// Any sub-class of Category must also have its own implementation of
// CategoryFactory.
public static class XFactory implements CategoryFactory {
+
+ static String INSTANCE_FQCN = XCategory.class.getName();
+
public XFactory() {
}
public
Category makeNewCategoryInstance(String name) {
- return new XCategory(name);
+ return new XCategory(name, INSTANCE_FQCN);
}
}
}