1
0

Add feature to disable loading of Log implementations from the TCCL.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@370030 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Kitching
2006-01-18 03:38:38 +00:00
parent aecdf1ebec
commit 1b6895e3c5

View File

@@ -159,6 +159,11 @@ public class LogFactoryImpl extends LogFactory {
// ----------------------------------------------------- Instance Variables // ----------------------------------------------------- Instance Variables
/**
* Determines whether logging classes should be loaded using the thread-context
* classloader, or via the classloader that loaded this LogFactoryImpl class.
*/
private boolean useTCCL = true;
/** /**
* The string prefixed to every message output by the logDiagnostic method. * The string prefixed to every message output by the logDiagnostic method.
@@ -375,6 +380,10 @@ public class LogFactoryImpl extends LogFactory {
} else { } else {
attributes.put(name, value); attributes.put(name, value);
} }
if (name.equals(TCCL_KEY)) {
useTCCL = Boolean.valueOf(value.toString()).booleanValue();
}
} }
@@ -699,7 +708,6 @@ public class LogFactoryImpl extends LogFactory {
String specifiedLogClassName = findUserSpecifiedLogClassName(); String specifiedLogClassName = findUserSpecifiedLogClassName();
if (specifiedLogClassName != null) { if (specifiedLogClassName != null) {
// note: createLogFromClass never returns null..
result = createLogFromClass(specifiedLogClassName, result = createLogFromClass(specifiedLogClassName,
logCategory, logCategory,
true); true);
@@ -834,7 +842,7 @@ public class LogFactoryImpl extends LogFactory {
Class c = Class.forName(logAdapterClassName, true, currentCL); Class c = Class.forName(logAdapterClassName, true, currentCL);
constructor = c.getConstructor(logConstructorSignature); constructor = c.getConstructor(logConstructorSignature);
Object o = constructor.newInstance(params); Object o = constructor.newInstance(params);
// Note that we do this test after trying to create an instance // Note that we do this test after trying to create an instance
// [rather than testing Log.class.isAssignableFrom(c)] so that // [rather than testing Log.class.isAssignableFrom(c)] so that
// we don't complain about Log hierarchy problems when the // we don't complain about Log hierarchy problems when the
@@ -969,12 +977,17 @@ public class LogFactoryImpl extends LogFactory {
* *
*/ */
private ClassLoader getBaseClassLoader() throws LogConfigurationException { private ClassLoader getBaseClassLoader() throws LogConfigurationException {
ClassLoader contextClassLoader = getContextClassLoader();
ClassLoader thisClassLoader = getClassLoader(LogFactoryImpl.class); ClassLoader thisClassLoader = getClassLoader(LogFactoryImpl.class);
if (useTCCL == false) {
return thisClassLoader;
}
ClassLoader contextClassLoader = getContextClassLoader();
ClassLoader baseClassLoader = getLowestClassLoader( ClassLoader baseClassLoader = getLowestClassLoader(
contextClassLoader, thisClassLoader); contextClassLoader, thisClassLoader);
if (baseClassLoader == null) { if (baseClassLoader == null) {
// The two classloaders are not part of a parent child relationship. // The two classloaders are not part of a parent child relationship.
// In some classloading setups (e.g. JBoss with its // In some classloading setups (e.g. JBoss with its