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 $
|
* $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.4 $
|
* $Revision: 1.5 $
|
||||||
* $Date: 2002/02/14 21:09:19 $
|
* $Date: 2002/02/26 19:00:27 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
@@ -84,7 +84,7 @@ import java.util.Properties;
|
|||||||
*
|
*
|
||||||
* @author Craig R. McClanahan
|
* @author Craig R. McClanahan
|
||||||
* @author Costin Manolache
|
* @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 {
|
public abstract class LogFactory {
|
||||||
@@ -483,21 +483,29 @@ public abstract class LogFactory {
|
|||||||
*/
|
*/
|
||||||
protected static LogFactory newFactory(String factoryClass,
|
protected static LogFactory newFactory(String factoryClass,
|
||||||
ClassLoader classLoader)
|
ClassLoader classLoader)
|
||||||
throws LogConfigurationException {
|
throws LogConfigurationException
|
||||||
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class clazz = null;
|
Class clazz = null;
|
||||||
if (classLoader == null) {
|
if (classLoader == null) {
|
||||||
clazz = Class.forName(factoryClass);
|
clazz = Class.forName(factoryClass);
|
||||||
} else {
|
} 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());
|
return ((LogFactory) clazz.newInstance());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
throw new LogConfigurationException(e);
|
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 $
|
* $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.4 $
|
* $Revision: 1.5 $
|
||||||
* $Date: 2002/02/15 05:42:35 $
|
* $Date: 2002/02/26 19:00:27 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
@@ -104,7 +104,7 @@ import org.apache.commons.logging.LogSource;
|
|||||||
*
|
*
|
||||||
* @author Rod Waldhoff
|
* @author Rod Waldhoff
|
||||||
* @author Craig R. McClanahan
|
* @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 {
|
public class LogFactoryImpl extends LogFactory {
|
||||||
@@ -395,7 +395,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// Attempt to load the Log implementation class
|
// Attempt to load the Log implementation class
|
||||||
Class logClass = null;
|
Class logClass = null;
|
||||||
try {
|
try {
|
||||||
logClass = findClassLoader().loadClass(logClassName);
|
logClass = loadClass(logClassName);
|
||||||
if (!Log.class.isAssignableFrom(logClass)) {
|
if (!Log.class.isAssignableFrom(logClass)) {
|
||||||
throw new LogConfigurationException
|
throw new LogConfigurationException
|
||||||
("Class " + logClassName + " does not implement Log");
|
("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() {
|
protected void guessConfig() {
|
||||||
if( isLog4JAvailable() ) {
|
if( isLog4JAvailable() ) {
|
||||||
try {
|
try {
|
||||||
Class proxyClass=findClassLoader().
|
Class proxyClass=
|
||||||
loadClass( "org.apache.commons.logging.Log4jFactory" );
|
loadClass( "org.apache.commons.logging.Log4jFactory" );
|
||||||
proxyFactory=(LogFactory)proxyClass.newInstance();
|
proxyFactory=(LogFactory)proxyClass.newInstance();
|
||||||
} catch( Throwable t ) {
|
} catch( Throwable t ) {
|
||||||
@@ -444,7 +458,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
protected boolean isJdk14Available() {
|
protected boolean isJdk14Available() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
findClassLoader().loadClass("java.util.logging.Logger");
|
loadClass("java.util.logging.Logger");
|
||||||
return (true);
|
return (true);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
return (false);
|
return (false);
|
||||||
@@ -459,7 +473,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
protected boolean isLog4JAvailable() {
|
protected boolean isLog4JAvailable() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
findClassLoader().loadClass("org.apache.log4j.Category");
|
loadClass("org.apache.log4j.Category");
|
||||||
return (true);
|
return (true);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
return (false);
|
return (false);
|
||||||
|
|||||||
Reference in New Issue
Block a user