diff --git a/src/java/org/apache/commons/logging/LogFactory.java b/src/java/org/apache/commons/logging/LogFactory.java
index badf32d..14f63e4 100644
--- a/src/java/org/apache/commons/logging/LogFactory.java
+++ b/src/java/org/apache/commons/logging/LogFactory.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogFactory.java,v 1.1 2002/02/13 02:18:11 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2002/02/13 02:18:11 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogFactory.java,v 1.2 2002/02/14 00:19:03 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/02/14 00:19:03 $
*
* ====================================================================
*
@@ -67,6 +67,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;
+import java.util.Hashtable;
import java.util.Properties;
@@ -81,7 +82,7 @@ import java.util.Properties;
*
* @author Craig R. McClanahan
* @author Costin Manolache
- * @version $Revision: 1.1 $ $Date: 2002/02/13 02:18:11 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/14 00:19:03 $
*/
public abstract class LogFactory {
@@ -142,10 +143,29 @@ public abstract class LogFactory {
public abstract String[] getAttributeNames();
+ /**
+ * Convenience method to derive a name from the specified class and
+ * call getInstance(String) with it.
+ *
+ * @param clazz Class for which a suitable Log name will be derived
+ *
+ * @exception LogConfigurationException if a suitable Log
+ * instance cannot be returned
+ */
+ public abstract Log getInstance(Class clazz)
+ throws LogConfigurationException;
+
+
/**
*
Construct (if necessary) and return a Log instance,
* using the factory's current set of configuration attributes.
NOTE - Depending upon the implementation of
+ * the LogFactory you are using, the Log
+ * instance you are returned may or may not be local to the current
+ * application, and may or may not be returned again on a subsequent
+ * call with the same name argument.
Log instance to be
* returned (the meaning of this name is only known to the underlying
* logging implementation that is being wrapped)
@@ -157,6 +177,16 @@ public abstract class LogFactory {
throws LogConfigurationException;
+ /**
+ * Release any internal references to previously created {@link Log}
+ * instances returned by this factory. This is useful environments
+ * like servlet containers, which implement application reloading by
+ * throwing away a ClassLoader. Dangling references to objects in that
+ * class loader would prevent garbage collection.
+ */
+ public abstract void release();
+
+
/**
* Remove any configuration attribute associated with the specified name.
* If there is no such attribute, no action is taken.
@@ -178,13 +208,23 @@ public abstract class LogFactory {
public abstract void setAttribute(String name, Object value);
+ // ------------------------------------------------------- Static Variables
+
+
+ /**
+ * The previously constructed LogFactory instances, keyed by
+ * the ClassLoader with which it was created.
+ */
+ protected static Hashtable factories = new Hashtable();
+
+
// --------------------------------------------------------- Static Methods
/**
- * Construct and return a new LogFactory instance, using
- * the following ordered lookup procedure to determine the name of the
- * implementation class to be loaded:
Construct (if necessary) and return a LogFactory
+ * instance, using the following ordered lookup procedure to determine
+ * the name of the implementation class to be loaded:
org.apache.commons.logging.LogFactory system
* property.Log
+ * instance cannot be returned
+ */
+ public static Log getLog(Class clazz)
+ throws LogConfigurationException {
+
+ return (getFactory().getInstance(clazz));
+
+ }
+
+
+ /**
+ * Convenience method to return a named logger, without the application
+ * having to care about factories.
+ *
+ * @param name Logical name of the Log instance to be
+ * returned (the meaning of this name is only known to the underlying
+ * logging implementation that is being wrapped)
+ *
+ * @exception LogConfigurationException if a suitable Log
+ * instance cannot be returned
+ */
+ public static Log getLog(String name)
+ throws LogConfigurationException {
+
+ return (getFactory().getInstance(name));
+
+ }
+
+
+ /**
+ * Release any internal references to previously created {@link LogFactory}
+ * instances, after calling the instance method release() on
+ * each of them. This is useful environments like servlet containers,
+ * which implement application reloading by throwing away a ClassLoader.
+ * Dangling references to objects in that class loader would prevent
+ * garbage collection.
+ */
+ public static void releaseAll() {
+
+ synchronized (factories) {
+ Enumeration elements = factories.elements();
+ while (elements.hasMoreElements()) {
+ LogFactory element = (LogFactory) elements.nextElement();
+ element.release();
+ }
+ factories.clear();
+ }
}
@@ -308,8 +418,8 @@ public abstract class LogFactory {
* @exception LogConfigurationException if a suitable instance
* cannot be created
*/
- private static LogFactory newInstance(String factoryClass,
- ClassLoader classLoader)
+ protected static LogFactory newFactory(String factoryClass,
+ ClassLoader classLoader)
throws LogConfigurationException {
try {
diff --git a/src/java/org/apache/commons/logging/LogSource.java b/src/java/org/apache/commons/logging/LogSource.java
index 63082d4..8745994 100644
--- a/src/java/org/apache/commons/logging/LogSource.java
+++ b/src/java/org/apache/commons/logging/LogSource.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogSource.java,v 1.12 2002/02/03 01:31:54 sanders Exp $
- * $Revision: 1.12 $
- * $Date: 2002/02/03 01:31:54 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogSource.java,v 1.13 2002/02/14 00:19:03 craigmcc Exp $
+ * $Revision: 1.13 $
+ * $Date: 2002/02/14 00:19:03 $
*
* ====================================================================
*
@@ -93,8 +93,11 @@ import org.apache.commons.logging.impl.NoOpLog;
* LogSource.setLogImplementation().getInstance(String) with it.
+ *
+ * @param clazz Class for which a suitable Log name will be derived
+ *
+ * @exception LogConfigurationException if a suitable Log
+ * instance cannot be returned
+ */
+ public Log getInstance(Class clazz)
+ throws LogConfigurationException {
+
+ return (getInstance(clazz.getName()));
+
+ }
+
+
/**
* Construct (if necessary) and return a Log instance,
* using the factory's current set of configuration attributes.
NOTE - Depending upon the implementation of
+ * the LogFactory you are using, the Log
+ * instance you are returned may or may not be local to the current
+ * application, and may or may not be returned again on a subsequent
+ * call with the same name argument.
Log instance to be
* returned (the meaning of this name is only known to the underlying
* logging implementation that is being wrapped)
@@ -252,6 +275,20 @@ public class LogFactoryImpl extends LogFactory {
}
+ /**
+ * Release any internal references to previously created {@link Log}
+ * instances returned by this factory. This is useful environments
+ * like servlet containers, which implement application reloading by
+ * throwing away a ClassLoader. Dangling references to objects in that
+ * class loader would prevent garbage collection.
+ */
+ public void release() {
+
+ instances.clear();
+
+ }
+
+
/**
* Remove any configuration attribute associated with the specified name.
* If there is no such attribute, no action is taken.