pglezen 01/06/04 21:41:00
Modified: src/java/org/apache/log4j/examples/appserver
AppServerCategoryFactory.java package.html
Log:
1. AppServerCategoryFactory - ctor changed to automatically
install itself as the default factory for use by the
AppServerCategory.getInstance(String).
2. package.html - changed configuration instructions to reflect
change #1.
Revision Changes Path
1.6 +7 -2
jakarta-log4j/src/java/org/apache/log4j/examples/appserver/AppServerCategoryFactory.java
Index: AppServerCategoryFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/examples/appserver/AppServerCategoryFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AppServerCategoryFactory.java 2001/06/04 06:15:21 1.5
+++ AppServerCategoryFactory.java 2001/06/05 04:40:58 1.6
@@ -52,7 +52,10 @@
/**
* Construct a new <code>AppServerCategoryFactory</code> with
* the provided attributes. An attempt is made to obtain the
- * hostname from the java.net API.
+ * hostname from the java.net API. This constructor sets the
+ * newly created instance as the default factory for future
+ * invocations of {@link AppServerCategory#getInstance(String)}
+ * via {@link AppServerCategory#setFactory}.
*
* @param categoryName the name of the category.
* @param serverName the name of the server using this category. This
@@ -67,11 +70,13 @@
try {
hostname = java.net.InetAddress.getLocalHost().getHostName();
} catch ( java.net.UnknownHostException uhe ) {
- System.err.println("AppServerCategoryFactory: could not determine local
hostname.");
+ LogLog.warn("AppServerCategoryFactory: could not determine local hostname.");
}
server = serverName;
component = componentName;
version = versionName;
+
+ AppServerCategory.setFactory(this);
}
/**
1.6 +17 -36
jakarta-log4j/src/java/org/apache/log4j/examples/appserver/package.html
Index: package.html
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/examples/appserver/package.html,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- package.html 2001/06/04 06:15:22 1.5
+++ package.html 2001/06/05 04:40:58 1.6
@@ -55,6 +55,7 @@
log4j.appender.stdout.layout.ConversionPattern=[%h:%s:%b:%v] %m%n
</pre></table>
<p>
+<!--
There is <b>no</b> need to change your source code to go from using
<code>Category</code> to <code>AppServerCategory</code> if you are
using property files to configure your logging infrastructure.
@@ -64,6 +65,11 @@
as the default factory for the hierarchy so that
{@link org.apache.log4j.Category#getInstance(String)} always returns
the proper <code>Category</code> subclass.
+ -->
+The only change needed to your source file is to invoke the {@link
+org.apache.log4j.examples.appserver.AppServerCategory#getInstance(String)}
+instead of the usual {@link org.apache.log4j.Category#getInstance(String)}
+to acquire an implementation of <code>Category</code>.
<h3>Manual Configuration</h3>
You can manually invoke the configuration much like the static
@@ -73,16 +79,13 @@
<tr><td><pre>
import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
-
+import org.apache.log4j.examples.appserver.AppServerCategory;
...
-
PropertyConfigurator.configure("test.properties");
-Category cat = Category.getInstance("some.cat");
-
+Category cat = AppServerCategory.getInstance("some.cat");
...
-
-cat.info("This is an INFO statement.");</pre>
-</table>
+cat.info("This is an INFO statement.");
+</pre> </table>
<p>
<h3>Very Manual Configuration</h3>
If you want complete control over the configuration process, you
@@ -90,45 +93,23 @@
together. This could be useful if you want only some of your
categories to be <code>AppServerCategory</code> instances.
<p>
-After creating an appropriate <code>AppServerCategoryFactory</code>
-instance, set a static reference to it using {@link
-org.apache.log4j.examples.appserver.AppServerCategory#setFactory}.
-This sets everything up for acquiring an <code>AppServerCategory</code>
-reference whenever you need one. When you use this method of
-configuration, the hierarchy's default factory is left alone. So
-you should use {@link
-org.apache.log4j.examples.appserver.AppServerCategory#getInstance(String)}
-to acquire a reference to an <code>AppServerCategory</code> instance.
+Simply create an <code>AppServerCategoryFactory</code> instance.
+The constructor automatically installs the new instance as the
+default factory for future calls to {@link
+org.apache.log4j.examples.appserver.AppServerCategory#getInstance(String)}.
<p>
<table border=1>
<tr><td><pre>
-import org.apache.log4j.spi.CategoryFactory;
import org.apache.log4j.Category;
import org.apache.log4j.examples.appserver.AppServerCategoryFactory;
import org.apache.log4j.examples.appserver.AppServerCategory;
-
...
-
org.apache.log4j.BasicConfigurator.configure();
-CategoryFactory factory = new AppServerCategoryFactory("MyServer", null, null);
-AppServerCategory.setFactory( factory );
-
+new AppServerCategoryFactory("MyServer", null, null);
...
-
Category cat = AppServerCategory.getInstance("my.category");
-cat.info("Entry");
-</pre>
-</table>
-<p>
-Do <b>not</b> use {@link
-org.apache.log4j.examples.appserver.AppServerCategory#getInstance(String)}
-to acquire an <code>AppServerCategory</code> instance if you used
-<code>PropertyConfigurator</code> to do the configuration. While the
-introspection mechanism used by <code>PropertyConfigurator</code> is good,
-it doesn't know to set a link from <code>AppServerCategory</code> to
-the factory. Misusing the <code>getInstance</code> method in this manner
-will result in categories produced that have host name defined but all
-other attributes set to null.
+cat.info("Entry");
+</pre> </table>
<p>
<h4>A Note on Configurators</h4>
Using the <i>very manual</i> approach to configure
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]