diff --git a/build.xml b/build.xml
index 7efe7b2..c868222 100644
--- a/build.xml
+++ b/build.xml
@@ -3,7 +3,7 @@
@@ -129,12 +129,17 @@
Implementation of the Factory for creating {@link Log} instances. Applications should call
- * the {@link #makeNewLogInstance} method to instantiate new instances
+ * the By default, calling You can change the default behavior in one of two ways:org.apache.commons.logging.Log
+ * interfaces that wraps the standard JDK logging mechanisms that were
+ * introduced in the Merlin release (JDK 1.4).makeNewLogInstance() method to instantiate new instances
* of the configured {@link Log} implementation class.getInstance() will use the following
+ * algorithm:
+ *
+ *
+ * org.apache.commons.logging.Log4JCategoryLog.org.apache.commons.logging.Jdk14Logger.org.apache.commons.logging.NoOpLog.
+ *
+ *
* @author Rod Waldhoff
- * @version $Id: LogSource.java,v 1.6 2002/01/05 15:55:00 rdonkin Exp $
+ * @version $Id: LogSource.java,v 1.7 2002/01/05 22:40:40 craigmcc Exp $
*/
public class LogSource {
- // --------------------------------------------------------- Class Attributes
+ // ------------------------------------------------------- Class Attributes
static protected HashMap _logs = new HashMap();
+
/** Is log4j available (in the current classpath) */
static protected boolean _log4jIsAvailable = false;
+
+ /** Is JD 1.4 logging available */
+ static protected boolean _jdk14IsAvailable = false;
-
- // --------------------------------------------------------- Class Initializers
+ /** Constructor for current log class */
+ static protected Constructor _logimplctor = null;
+
+
+ // ----------------------------------------------------- Class Initializers
static {
+
+ // Is Log4J Available?
try {
if(null != Class.forName("org.apache.log4j.Category")) {
_log4jIsAvailable = true;
} else {
_log4jIsAvailable = false;
}
- } catch(ClassNotFoundException e) {
- _log4jIsAvailable = false;
- } catch(ExceptionInInitializerError e) {
- _log4jIsAvailable = false;
- } catch(LinkageError e) {
+ } catch (Throwable t) {
_log4jIsAvailable = false;
}
- }
- /** Constructor for current log class */
- static protected Constructor _logimplctor = null;
- static {
+ // Is JDK 1.4 Logging Available?
try {
- setLogImplementation(
- System.getProperty(
- "org.apache.commons.logging.log","org.apache.commons.logging.NoOpLog"));
-
- } catch(SecurityException e) {
- _logimplctor = null;
- } catch(LinkageError e) {
- _logimplctor = null;
- } catch(NoSuchMethodException e) {
- _logimplctor = null;
- } catch(ClassNotFoundException e) {
- _logimplctor = null;
+ if(null != Class.forName("java.util.logging.Logger")) {
+ _jdk14IsAvailable = true;
+ } else {
+ _jdk14IsAvailable = false;
+ }
+ } catch (Throwable t) {
+ _jdk14IsAvailable = false;
}
+
+ // Set the default Log implementation
+ String name =
+ System.getProperty("org.apache.commons.logging.log");
+ if (name != null) {
+ try {
+ setLogImplementation(name);
+ } catch (Throwable t) {
+ try {
+ setLogImplementation
+ ("org.apache.commons.logging.NoOpLog");
+ } catch (Throwable u) {
+ ;
+ }
+ }
+ } else {
+ try {
+ if (_log4jIsAvailable) {
+ setLogImplementation
+ ("org.apache.commons.logging.Log4JCategoryLog");
+ } else if (_jdk14IsAvailable) {
+ setLogImplementation
+ ("org.apache.commons.logging.Jdk14Logger");
+ } else {
+ setLogImplementation
+ ("org.apache.commons.logging.NoOpLog");
+ }
+ } catch (Throwable t) {
+ try {
+ setLogImplementation
+ ("org.apache.commons.logging.NoOpLog");
+ } catch (Throwable u) {
+ ;
+ }
+ }
+ }
+
}
- // --------------------------------------------------------- Constructor
+ // ------------------------------------------------------------ Constructor
+
/** Don't allow others to create instances */
private LogSource() {
}
- // --------------------------------------------------------- Class Methods
+
+ // ---------------------------------------------------------- Class Methods
+
/**
* Set the log implementation/log implementation factory
@@ -140,12 +197,17 @@ public class LogSource {
LinkageError, ExceptionInInitializerError,
NoSuchMethodException, SecurityException,
ClassNotFoundException {
- Class logclass = Class.forName(classname);
- Class[] argtypes = new Class[1];
- argtypes[0] = "".getClass();
- _logimplctor = logclass.getConstructor(argtypes);
+ try {
+ Class logclass = Class.forName(classname);
+ Class[] argtypes = new Class[1];
+ argtypes[0] = "".getClass();
+ _logimplctor = logclass.getConstructor(argtypes);
+ } catch (Throwable t) {
+ _logimplctor = null;
+ }
}
+
/**
* Set the log implementation/log implementation factory
* by class. The given class must implement {@link Log},
@@ -171,11 +233,13 @@ public class LogSource {
return log;
}
+
/** Get a org.apache.commons.logging.log to the name of the
+ * org.apache.commons.logging.Log implementation class
+ * you want to use.LogSource.setLogImplementation().Log instance by class */
static public Log getInstance(Class clazz) {
return getInstance(clazz.getName());
}
+
/**
* Create a new {@link Log} implementation, based
* on the given name
@@ -194,36 +258,27 @@ public class LogSource {
* or when no corresponding class can be found,
* this method will return a {@link Log4JCategoryLog}
* if the log4j {@link org.apache.log4j.Category} class is
- * available in the {@link LogSource}'s classpath, or
- * a {@link NoOpLog} if it is not.
+ * available in the {@link LogSource}'s classpath, or a
+ * {@link Jdk14Logger} if we are on a JDK 1.4 or later system, or
+ * a {@link NoOpLog} if neither of the above conditions is true.
*
* @param name the log name (or category)
*/
static public Log makeNewLogInstance(String name) {
+
Log log = null;
try {
Object[] args = new Object[1];
args[0] = name;
log = (Log)(_logimplctor.newInstance(args));
- } catch (InstantiationException e) {
- log = null;
- } catch (IllegalAccessException e) {
- log = null;
- } catch (IllegalArgumentException e) {
- log = null;
- } catch (InvocationTargetException e) {
- log = null;
- } catch (NullPointerException e) {
+ } catch (Throwable t) {
log = null;
}
if(null == log) {
- if(_log4jIsAvailable) {
- return new Log4JCategoryLog(name);
- } else {
- log = new NoOpLog(name);
- }
+ log = new NoOpLog(name);
}
return log;
+
}
/**
diff --git a/src/java/org/apache/commons/logging/package.html b/src/java/org/apache/commons/logging/package.html
index 123daba..21cec49 100644
--- a/src/java/org/apache/commons/logging/package.html
+++ b/src/java/org/apache/commons/logging/package.html
@@ -10,12 +10,10 @@ prebuilt support for the following: