1
0

Bugzilla Defect 10825 [thanks for the patch & the education!]

Added real text & exceptions to tests.. it's harder to read :-(


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard A. Sitze
2002-10-17 23:00:04 +00:00
parent 8c5d183b40
commit 03368dd582
2 changed files with 39 additions and 34 deletions

View File

@@ -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.12 2002/08/30 03:23:34 rsitze Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogFactory.java,v 1.13 2002/10/17 23:00:04 rsitze Exp $
* $Revision: 1.12 $ * $Revision: 1.13 $
* $Date: 2002/08/30 03:23:34 $ * $Date: 2002/10/17 23:00:04 $
* *
* ==================================================================== * ====================================================================
* *
@@ -86,7 +86,7 @@ import java.util.Properties;
* *
* @author Craig R. McClanahan * @author Craig R. McClanahan
* @author Costin Manolache * @author Costin Manolache
* @version $Revision: 1.12 $ $Date: 2002/08/30 03:23:34 $ * @version $Revision: 1.13 $ $Date: 2002/10/17 23:00:04 $
*/ */
public abstract class LogFactory { public abstract class LogFactory {
@@ -534,29 +534,34 @@ public abstract class LogFactory {
{ {
try { try {
if (classLoader == null)
classLoader = LogFactory.class.getClassLoader();
Class clazz = null; Class clazz = null;
if (classLoader != null) {
try { try {
// first the thread class loader // first the given class loader param (thread class loader)
clazz = classLoader.loadClass(factoryClass); return (LogFactory)classLoader.loadClass(factoryClass).newInstance();
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
// if this failed (i.e. no implementation is if (classLoader == LogFactory.class.getClassLoader()) {
// found in the webapp), try the caller's loader // Nothing more to try, onwards.
// if we haven't already... throw ex;
if (classLoader != LogFactory.class.getClassLoader()) { }
classLoader = LogFactory.class.getClassLoader(); // ignore exception, continue
clazz = classLoader.loadClass(factoryClass);
} }
} }
LogFactory factory = (LogFactory)clazz.newInstance(); /* At this point, either classLoader == null, OR
* classLoader was unable to load factoryClass..
return factory; * try the class loader that loaded this class:
* LogFactory.getClassLoader().
*
* Notes:
* a) LogFactory.class.getClassLoader() may return 'null'
* if LogFactory is loaded by the bootstrap classloader.
* b) The Java endorsed library mechanism is instead
* Class.forName(factoryClass);
*/
return (LogFactory)Class.forName(factoryClass).newInstance();
} catch (Exception e) { } catch (Exception e) {
throw new LogConfigurationException(e); throw new LogConfigurationException(e);
} }
} }
} }

View File

@@ -86,29 +86,29 @@ public abstract class AbstractLogTest extends TestCase {
assertNotNull(log); assertNotNull(log);
log.debug(null); log.debug("debug statement");
log.debug(null, null); log.debug("debug statement w/ null exception", new RuntimeException());
log.error(null); log.error("error statement");
log.error(null, null); log.error("error statement w/ null exception", new RuntimeException());
log.fatal(null); log.fatal("fatal statement");
log.fatal(null, null); log.fatal("fatal statement w/ null exception", new RuntimeException());
log.info(null); log.info("info statement");
log.info(null, null); log.info("info statement w/ null exception", new RuntimeException());
log.trace(null); log.trace("trace statement");
log.trace(null, null); log.trace("trace statement w/ null exception", new RuntimeException());
log.warn(null); log.warn("warn statement");
log.warn(null, null); log.warn("warn statement w/ null exception", new RuntimeException());
} }
} }