Deal with the posiblity that a commons-logging is loaded in
a loader, and the thread loader is set to point to a different loader that doesn't include logging ( or to a wrong value ). This happens when logging is used in certain container components, where the thread loader will point to an app that may not have/use logging. XXX What's the right order ? From a 'feature' point of view, it's better to try the thread loader first, so apps can override the default. From a security point of view, we should try the Class.forName() first, i.e. whatever is loaded in the parent loader. The current fix leaves the original order ( with thread loader used if available ). git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138874 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -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.4 2002/02/14 21:09:19 costin Exp $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/02/14 21:09:19 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogFactory.java,v 1.5 2002/02/26 19:00:27 costin Exp $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2002/02/26 19:00:27 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
@@ -84,7 +84,7 @@ import java.util.Properties;
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @author Costin Manolache
|
||||
* @version $Revision: 1.4 $ $Date: 2002/02/14 21:09:19 $
|
||||
* @version $Revision: 1.5 $ $Date: 2002/02/26 19:00:27 $
|
||||
*/
|
||||
|
||||
public abstract class LogFactory {
|
||||
@@ -483,21 +483,29 @@ public abstract class LogFactory {
|
||||
*/
|
||||
protected static LogFactory newFactory(String factoryClass,
|
||||
ClassLoader classLoader)
|
||||
throws LogConfigurationException {
|
||||
throws LogConfigurationException
|
||||
{
|
||||
|
||||
try {
|
||||
Class clazz = null;
|
||||
if (classLoader == null) {
|
||||
clazz = Class.forName(factoryClass);
|
||||
} else {
|
||||
clazz = classLoader.loadClass(factoryClass);
|
||||
try {
|
||||
// first the thread class loader
|
||||
clazz = classLoader.loadClass(factoryClass);
|
||||
} catch( ClassNotFoundException ex ) {
|
||||
// if this failed ( i.e. no implementation is
|
||||
// found in the webapp itself ) try the
|
||||
// caller's loader
|
||||
clazz = Class.forName( factoryClass );
|
||||
}
|
||||
}
|
||||
return ((LogFactory) clazz.newInstance());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new LogConfigurationException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v 1.4 2002/02/15 05:42:35 costin Exp $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/02/15 05:42:35 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v 1.5 2002/02/26 19:00:27 costin Exp $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2002/02/26 19:00:27 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
@@ -104,7 +104,7 @@ import org.apache.commons.logging.LogSource;
|
||||
*
|
||||
* @author Rod Waldhoff
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision: 1.4 $ $Date: 2002/02/15 05:42:35 $
|
||||
* @version $Revision: 1.5 $ $Date: 2002/02/26 19:00:27 $
|
||||
*/
|
||||
|
||||
public class LogFactoryImpl extends LogFactory {
|
||||
@@ -395,7 +395,7 @@ public class LogFactoryImpl extends LogFactory {
|
||||
// Attempt to load the Log implementation class
|
||||
Class logClass = null;
|
||||
try {
|
||||
logClass = findClassLoader().loadClass(logClassName);
|
||||
logClass = loadClass(logClassName);
|
||||
if (!Log.class.isAssignableFrom(logClass)) {
|
||||
throw new LogConfigurationException
|
||||
("Class " + logClassName + " does not implement Log");
|
||||
@@ -423,10 +423,24 @@ public class LogFactoryImpl extends LogFactory {
|
||||
|
||||
}
|
||||
|
||||
/** Load a class, try first the thread class loader, and
|
||||
if it fails use the loader that loaded this class
|
||||
*/
|
||||
static Class loadClass( String name )
|
||||
throws ClassNotFoundException
|
||||
{
|
||||
ClassLoader threadCL=findClassLoader();
|
||||
try {
|
||||
return threadCL.loadClass(name);
|
||||
} catch( ClassNotFoundException ex ) {
|
||||
return Class.forName( name );
|
||||
}
|
||||
}
|
||||
|
||||
protected void guessConfig() {
|
||||
if( isLog4JAvailable() ) {
|
||||
try {
|
||||
Class proxyClass=findClassLoader().
|
||||
Class proxyClass=
|
||||
loadClass( "org.apache.commons.logging.Log4jFactory" );
|
||||
proxyFactory=(LogFactory)proxyClass.newInstance();
|
||||
} catch( Throwable t ) {
|
||||
@@ -444,7 +458,7 @@ public class LogFactoryImpl extends LogFactory {
|
||||
protected boolean isJdk14Available() {
|
||||
|
||||
try {
|
||||
findClassLoader().loadClass("java.util.logging.Logger");
|
||||
loadClass("java.util.logging.Logger");
|
||||
return (true);
|
||||
} catch (Throwable t) {
|
||||
return (false);
|
||||
@@ -459,7 +473,7 @@ public class LogFactoryImpl extends LogFactory {
|
||||
protected boolean isLog4JAvailable() {
|
||||
|
||||
try {
|
||||
findClassLoader().loadClass("org.apache.log4j.Category");
|
||||
loadClass("org.apache.log4j.Category");
|
||||
return (true);
|
||||
} catch (Throwable t) {
|
||||
return (false);
|
||||
|
||||
Reference in New Issue
Block a user