Added guards around diagnostic logging. Is unlikely to have much effect on real life performance but is good practice and should stop questions.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@377229 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -386,7 +386,9 @@ public abstract class LogFactory {
|
|||||||
// This is an odd enough situation to report about. This
|
// This is an odd enough situation to report about. This
|
||||||
// output will be a nuisance on JDK1.1, as the system
|
// output will be a nuisance on JDK1.1, as the system
|
||||||
// classloader is null in that environment.
|
// classloader is null in that environment.
|
||||||
logDiagnostic("Context classloader is null.");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Context classloader is null.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return any previously registered factory for this class loader
|
// Return any previously registered factory for this class loader
|
||||||
@@ -395,10 +397,12 @@ public abstract class LogFactory {
|
|||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"[LOOKUP] LogFactory implementation requested for the first time for context classloader "
|
logDiagnostic(
|
||||||
+ objectId(contextClassLoader));
|
"[LOOKUP] LogFactory implementation requested for the first time for context classloader "
|
||||||
logHierarchy("[LOOKUP] ", contextClassLoader);
|
+ objectId(contextClassLoader));
|
||||||
|
logHierarchy("[LOOKUP] ", contextClassLoader);
|
||||||
|
}
|
||||||
|
|
||||||
// Load properties file.
|
// Load properties file.
|
||||||
//
|
//
|
||||||
@@ -435,25 +439,31 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
// Determine which concrete LogFactory subclass to use.
|
// Determine which concrete LogFactory subclass to use.
|
||||||
// First, try a global system property
|
// First, try a global system property
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"[LOOKUP] Looking for system property [" + FACTORY_PROPERTY
|
logDiagnostic(
|
||||||
+ "] to define the LogFactory subclass to use...");
|
"[LOOKUP] Looking for system property [" + FACTORY_PROPERTY
|
||||||
|
+ "] to define the LogFactory subclass to use...");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String factoryClass = System.getProperty(FACTORY_PROPERTY);
|
String factoryClass = System.getProperty(FACTORY_PROPERTY);
|
||||||
if (factoryClass != null) {
|
if (factoryClass != null) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"[LOOKUP] Creating an instance of LogFactory class '" + factoryClass
|
logDiagnostic(
|
||||||
+ "' as specified by system property " + FACTORY_PROPERTY);
|
"[LOOKUP] Creating an instance of LogFactory class '" + factoryClass
|
||||||
|
+ "' as specified by system property " + FACTORY_PROPERTY);
|
||||||
|
}
|
||||||
|
|
||||||
factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
|
factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"[LOOKUP] A security exception occurred while trying to create an"
|
logDiagnostic(
|
||||||
+ " instance of the custom factory class"
|
"[LOOKUP] A security exception occurred while trying to create an"
|
||||||
+ ": [" + e.getMessage().trim()
|
+ " instance of the custom factory class"
|
||||||
+ "]. Trying alternative implementations...");
|
+ ": [" + e.getMessage().trim()
|
||||||
|
+ "]. Trying alternative implementations...");
|
||||||
|
}
|
||||||
; // ignore
|
; // ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,10 +475,11 @@ public abstract class LogFactory {
|
|||||||
// that implements the desired interface.
|
// that implements the desired interface.
|
||||||
|
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"[LOOKUP] Looking for a resource file of name [" + SERVICE_ID
|
logDiagnostic(
|
||||||
+ "] to define the LogFactory subclass to use...");
|
"[LOOKUP] Looking for a resource file of name [" + SERVICE_ID
|
||||||
|
+ "] to define the LogFactory subclass to use...");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
InputStream is = getResourceAsStream(contextClassLoader,
|
InputStream is = getResourceAsStream(contextClassLoader,
|
||||||
SERVICE_ID);
|
SERVICE_ID);
|
||||||
@@ -488,23 +499,24 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
if (factoryClassName != null &&
|
if (factoryClassName != null &&
|
||||||
! "".equals(factoryClassName)) {
|
! "".equals(factoryClassName)) {
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic(
|
logDiagnostic(
|
||||||
"[LOOKUP] Creating an instance of LogFactory class " + factoryClassName
|
"[LOOKUP] Creating an instance of LogFactory class " + factoryClassName
|
||||||
+ " as specified by file '" + SERVICE_ID
|
+ " as specified by file '" + SERVICE_ID
|
||||||
+ "' which was present in the path of the context"
|
+ "' which was present in the path of the context"
|
||||||
+ " classloader.");
|
+ " classloader.");
|
||||||
|
}
|
||||||
factory = newFactory(factoryClassName, baseClassLoader, contextClassLoader );
|
factory = newFactory(factoryClassName, baseClassLoader, contextClassLoader );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic(
|
||||||
"[LOOKUP] A security exception occurred while trying to create an"
|
"[LOOKUP] A security exception occurred while trying to create an"
|
||||||
+ " instance of the custom factory class"
|
+ " instance of the custom factory class"
|
||||||
+ ": [" + ex.getMessage().trim()
|
+ ": [" + ex.getMessage().trim()
|
||||||
+ "]. Trying alternative implementations...");
|
+ "]. Trying alternative implementations...");
|
||||||
|
}
|
||||||
; // ignore
|
; // ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -519,16 +531,18 @@ public abstract class LogFactory {
|
|||||||
// system property )
|
// system property )
|
||||||
|
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"[LOOKUP] Looking for a properties file of name '" + FACTORY_PROPERTIES
|
|
||||||
+ "' to define the LogFactory subclass to use...");
|
|
||||||
|
|
||||||
if (props != null) {
|
|
||||||
logDiagnostic(
|
logDiagnostic(
|
||||||
|
"[LOOKUP] Looking for a properties file of name '" + FACTORY_PROPERTIES
|
||||||
|
+ "' to define the LogFactory subclass to use...");
|
||||||
|
}
|
||||||
|
if (props != null) {
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic(
|
||||||
"[LOOKUP] Properties file found. Looking for property '"
|
"[LOOKUP] Properties file found. Looking for property '"
|
||||||
+ FACTORY_PROPERTY
|
+ FACTORY_PROPERTY
|
||||||
+ "' to define the LogFactory subclass to use...");
|
+ "' to define the LogFactory subclass to use...");
|
||||||
|
}
|
||||||
String factoryClass = props.getProperty(FACTORY_PROPERTY);
|
String factoryClass = props.getProperty(FACTORY_PROPERTY);
|
||||||
if (factoryClass != null) {
|
if (factoryClass != null) {
|
||||||
factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
|
factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
|
||||||
@@ -542,10 +556,12 @@ public abstract class LogFactory {
|
|||||||
// Fourth, try the fallback implementation class
|
// Fourth, try the fallback implementation class
|
||||||
|
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic(
|
||||||
"[LOOKUP] Loading the default LogFactory implementation '" + FACTORY_DEFAULT
|
"[LOOKUP] Loading the default LogFactory implementation '" + FACTORY_DEFAULT
|
||||||
+ "' via the same classloader that loaded this LogFactory"
|
+ "' via the same classloader that loaded this LogFactory"
|
||||||
+ " class (ie not looking in the context classloader).");
|
+ " class (ie not looking in the context classloader).");
|
||||||
|
}
|
||||||
|
|
||||||
// Note: unlike the above code which can try to load custom LogFactory
|
// Note: unlike the above code which can try to load custom LogFactory
|
||||||
// implementations via the TCCL, we don't try to load the default LogFactory
|
// implementations via the TCCL, we don't try to load the default LogFactory
|
||||||
@@ -625,7 +641,9 @@ public abstract class LogFactory {
|
|||||||
*/
|
*/
|
||||||
public static void release(ClassLoader classLoader) {
|
public static void release(ClassLoader classLoader) {
|
||||||
|
|
||||||
logDiagnostic("Releasing factory for classloader " + objectId(classLoader));
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Releasing factory for classloader " + objectId(classLoader));
|
||||||
|
}
|
||||||
synchronized (factories) {
|
synchronized (factories) {
|
||||||
if (classLoader == null) {
|
if (classLoader == null) {
|
||||||
if (nullClassLoaderFactory != null) {
|
if (nullClassLoaderFactory != null) {
|
||||||
@@ -654,7 +672,9 @@ public abstract class LogFactory {
|
|||||||
*/
|
*/
|
||||||
public static void releaseAll() {
|
public static void releaseAll() {
|
||||||
|
|
||||||
logDiagnostic("Releasing factory for all classloaders.");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Releasing factory for all classloaders.");
|
||||||
|
}
|
||||||
synchronized (factories) {
|
synchronized (factories) {
|
||||||
Enumeration elements = factories.elements();
|
Enumeration elements = factories.elements();
|
||||||
while (elements.hasMoreElements()) {
|
while (elements.hasMoreElements()) {
|
||||||
@@ -700,9 +720,11 @@ public abstract class LogFactory {
|
|||||||
try {
|
try {
|
||||||
return clazz.getClassLoader();
|
return clazz.getClassLoader();
|
||||||
} catch(SecurityException ex) {
|
} catch(SecurityException ex) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Unable to get classloader for class " + clazz
|
logDiagnostic(
|
||||||
+ " due to security restrictions.");
|
"Unable to get classloader for class " + clazz
|
||||||
|
+ " due to security restrictions.");
|
||||||
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -937,16 +959,18 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
if (result instanceof LogConfigurationException) {
|
if (result instanceof LogConfigurationException) {
|
||||||
LogConfigurationException ex = (LogConfigurationException) result;
|
LogConfigurationException ex = (LogConfigurationException) result;
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"An error occurred while loading the factory class:"
|
logDiagnostic(
|
||||||
+ ex.getMessage());
|
"An error occurred while loading the factory class:"
|
||||||
|
+ ex.getMessage());
|
||||||
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic(
|
logDiagnostic(
|
||||||
"Created object " + objectId(result)
|
"Created object " + objectId(result)
|
||||||
+ " to manage classloader " + objectId(contextClassLoader));
|
+ " to manage classloader " + objectId(contextClassLoader));
|
||||||
|
}
|
||||||
return (LogFactory)result;
|
return (LogFactory)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -993,9 +1017,11 @@ public abstract class LogFactory {
|
|||||||
// to be generated/caught & recast properly.
|
// to be generated/caught & recast properly.
|
||||||
logFactoryClass = classLoader.loadClass(factoryClass);
|
logFactoryClass = classLoader.loadClass(factoryClass);
|
||||||
if (LogFactory.class.isAssignableFrom(logFactoryClass)) {
|
if (LogFactory.class.isAssignableFrom(logFactoryClass)) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Loaded class " + logFactoryClass.getName()
|
logDiagnostic(
|
||||||
+ " from classloader " + objectId(classLoader));
|
"Loaded class " + logFactoryClass.getName()
|
||||||
|
+ " from classloader " + objectId(classLoader));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// This indicates a problem with the ClassLoader tree.
|
// This indicates a problem with the ClassLoader tree.
|
||||||
@@ -1008,12 +1034,14 @@ public abstract class LogFactory {
|
|||||||
// problem is to remove the extra JCL jars from the
|
// problem is to remove the extra JCL jars from the
|
||||||
// ClassLoader hierarchy.
|
// ClassLoader hierarchy.
|
||||||
//
|
//
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Factory class " + logFactoryClass.getName()
|
logDiagnostic(
|
||||||
+ " loaded from classloader " + objectId(classLoader)
|
"Factory class " + logFactoryClass.getName()
|
||||||
+ " does not extend '" + LogFactory.class.getName()
|
+ " loaded from classloader " + objectId(classLoader)
|
||||||
+ "' as loaded by this classloader.");
|
+ " does not extend '" + LogFactory.class.getName()
|
||||||
logHierarchy("[BAD CL TREE] ", classLoader);
|
+ "' as loaded by this classloader.");
|
||||||
|
logHierarchy("[BAD CL TREE] ", classLoader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (LogFactory) logFactoryClass.newInstance();
|
return (LogFactory) logFactoryClass.newInstance();
|
||||||
@@ -1021,20 +1049,24 @@ public abstract class LogFactory {
|
|||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
if (classLoader == thisClassLoader) {
|
if (classLoader == thisClassLoader) {
|
||||||
// Nothing more to try, onwards.
|
// Nothing more to try, onwards.
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Unable to locate any class called '" + factoryClass
|
logDiagnostic(
|
||||||
+ "' via classloader " + objectId(classLoader));
|
"Unable to locate any class called '" + factoryClass
|
||||||
|
+ "' via classloader " + objectId(classLoader));
|
||||||
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
// ignore exception, continue
|
// ignore exception, continue
|
||||||
} catch (NoClassDefFoundError e) {
|
} catch (NoClassDefFoundError e) {
|
||||||
if (classLoader == thisClassLoader) {
|
if (classLoader == thisClassLoader) {
|
||||||
// Nothing more to try, onwards.
|
// Nothing more to try, onwards.
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Class '" + factoryClass + "' cannot be loaded"
|
logDiagnostic(
|
||||||
+ " via classloader " + objectId(classLoader)
|
"Class '" + factoryClass + "' cannot be loaded"
|
||||||
+ " - it depends on some other class that cannot"
|
+ " via classloader " + objectId(classLoader)
|
||||||
+ " be found.");
|
+ " - it depends on some other class that cannot"
|
||||||
|
+ " be found.");
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
// ignore exception, continue
|
// ignore exception, continue
|
||||||
@@ -1043,9 +1075,11 @@ public abstract class LogFactory {
|
|||||||
// This cast exception is not due to classloader issues;
|
// This cast exception is not due to classloader issues;
|
||||||
// the specified class *really* doesn't extend the
|
// the specified class *really* doesn't extend the
|
||||||
// required LogFactory base class.
|
// required LogFactory base class.
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Class '" + factoryClass + "' really does not extend '"
|
logDiagnostic(
|
||||||
+ LogFactory.class.getName() + "'");
|
"Class '" + factoryClass + "' really does not extend '"
|
||||||
|
+ LogFactory.class.getName() + "'");
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
// Ignore exception, continue
|
// Ignore exception, continue
|
||||||
@@ -1068,16 +1102,19 @@ public abstract class LogFactory {
|
|||||||
*/
|
*/
|
||||||
// Warning: must typecast here & allow exception
|
// Warning: must typecast here & allow exception
|
||||||
// to be generated/caught & recast properly.
|
// to be generated/caught & recast properly.
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic(
|
logDiagnostic(
|
||||||
"Unable to load factory class via classloader "
|
"Unable to load factory class via classloader "
|
||||||
+ objectId(classLoader)
|
+ objectId(classLoader)
|
||||||
+ " - trying the classloader associated with this LogFactory.");
|
+ " - trying the classloader associated with this LogFactory.");
|
||||||
|
}
|
||||||
logFactoryClass = Class.forName(factoryClass);
|
logFactoryClass = Class.forName(factoryClass);
|
||||||
return (LogFactory) logFactoryClass.newInstance();
|
return (LogFactory) logFactoryClass.newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Check to see if we've got a bad configuration
|
// Check to see if we've got a bad configuration
|
||||||
logDiagnostic("Unable to create LogFactory instance.");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Unable to create LogFactory instance.");
|
||||||
|
}
|
||||||
if (logFactoryClass != null
|
if (logFactoryClass != null
|
||||||
&& !LogFactory.class.isAssignableFrom(logFactoryClass)) {
|
&& !LogFactory.class.isAssignableFrom(logFactoryClass)) {
|
||||||
|
|
||||||
@@ -1137,9 +1174,11 @@ public abstract class LogFactory {
|
|||||||
return ClassLoader.getSystemResources(name);
|
return ClassLoader.getSystemResources(name);
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Exception while trying to find configuration file "
|
logDiagnostic(
|
||||||
+ name + ":" + e.getMessage());
|
"Exception while trying to find configuration file "
|
||||||
|
+ name + ":" + e.getMessage());
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch(NoSuchMethodError e) {
|
} catch(NoSuchMethodError e) {
|
||||||
// we must be running on a 1.1 JVM which doesn't support
|
// we must be running on a 1.1 JVM which doesn't support
|
||||||
@@ -1174,7 +1213,9 @@ public abstract class LogFactory {
|
|||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
logDiagnostic("Unable to read URL " + url);
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Unable to read URL " + url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -1234,7 +1275,9 @@ public abstract class LogFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
logDiagnostic("SecurityException thrown");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("SecurityException thrown");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
@@ -1400,6 +1443,9 @@ public abstract class LogFactory {
|
|||||||
* @param classLoader
|
* @param classLoader
|
||||||
*/
|
*/
|
||||||
private static void logHierarchy(String prefix, ClassLoader classLoader) {
|
private static void logHierarchy(String prefix, ClassLoader classLoader) {
|
||||||
|
if (!isDiagnosticsEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ClassLoader systemClassLoader;
|
ClassLoader systemClassLoader;
|
||||||
if (classLoader != null) {
|
if (classLoader != null) {
|
||||||
final String classLoaderString = classLoader.toString();
|
final String classLoaderString = classLoader.toString();
|
||||||
@@ -1483,6 +1529,8 @@ public abstract class LogFactory {
|
|||||||
initDiagnostics();
|
initDiagnostics();
|
||||||
logClassLoaderEnvironment(LogFactory.class);
|
logClassLoaderEnvironment(LogFactory.class);
|
||||||
factories = createFactoryStore();
|
factories = createFactoryStore();
|
||||||
logDiagnostic("BOOTSTRAP COMPLETED");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("BOOTSTRAP COMPLETED");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,9 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
public LogFactoryImpl() {
|
public LogFactoryImpl() {
|
||||||
super();
|
super();
|
||||||
initDiagnostics(); // method on this object
|
initDiagnostics(); // method on this object
|
||||||
logDiagnostic("Instance created.");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Instance created.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -637,7 +639,9 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* affect the future behaviour of this class.
|
* affect the future behaviour of this class.
|
||||||
*/
|
*/
|
||||||
private boolean isLogLibraryAvailable(String name, String classname) {
|
private boolean isLogLibraryAvailable(String name, String classname) {
|
||||||
logDiagnostic("Checking for " + name + ".");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Checking for " + name + ".");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Log log = createLogFromClass(
|
Log log = createLogFromClass(
|
||||||
classname,
|
classname,
|
||||||
@@ -645,14 +649,20 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
false);
|
false);
|
||||||
|
|
||||||
if (log == null) {
|
if (log == null) {
|
||||||
logDiagnostic("Did not find " + name + ".");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Did not find " + name + ".");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
logDiagnostic("Found " + name + ".");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Found " + name + ".");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch(LogConfigurationException e) {
|
} catch(LogConfigurationException e) {
|
||||||
logDiagnostic("Logging system " + name + " is available but not useable.");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Logging system " + name + " is available but not useable.");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -669,22 +679,33 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @return the value associated with the property, or null.
|
* @return the value associated with the property, or null.
|
||||||
*/
|
*/
|
||||||
private String getConfigurationValue(String property) {
|
private String getConfigurationValue(String property) {
|
||||||
logDiagnostic("[ENV] Trying to get configuration for item " + property);
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("[ENV] Trying to get configuration for item " + property);
|
||||||
logDiagnostic("[ENV] Looking for attribute " + property);
|
}
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("[ENV] Looking for attribute " + property);
|
||||||
|
}
|
||||||
Object valueObj = getAttribute(property);
|
Object valueObj = getAttribute(property);
|
||||||
if (valueObj != null) {
|
if (valueObj != null) {
|
||||||
logDiagnostic("[ENV] Found value [" + valueObj + "] for " + property);
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("[ENV] Found value [" + valueObj + "] for " + property);
|
||||||
|
}
|
||||||
return valueObj.toString();
|
return valueObj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
logDiagnostic("[ENV] Looking for system property " + property);
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("[ENV] Looking for system property " + property);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String value = System.getProperty(property);
|
String value = System.getProperty(property);
|
||||||
logDiagnostic("[ENV] Found value [" + value + "] for " + property);
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("[ENV] Found value [" + value + "] for " + property);
|
||||||
|
}
|
||||||
return value;
|
return value;
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
logDiagnostic("[ENV] Security prevented reading system property.");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("[ENV] Security prevented reading system property.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -727,7 +748,9 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
private Log discoverLogImplementation(String logCategory)
|
private Log discoverLogImplementation(String logCategory)
|
||||||
throws LogConfigurationException
|
throws LogConfigurationException
|
||||||
{
|
{
|
||||||
logDiagnostic("Attempting to discover a Log implementation.");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Attempting to discover a Log implementation.");
|
||||||
|
}
|
||||||
|
|
||||||
initConfiguration();
|
initConfiguration();
|
||||||
|
|
||||||
@@ -831,34 +854,46 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
*/
|
*/
|
||||||
private String findUserSpecifiedLogClassName()
|
private String findUserSpecifiedLogClassName()
|
||||||
{
|
{
|
||||||
logDiagnostic("Trying to get log class from attribute '" + LOG_PROPERTY + "'");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Trying to get log class from attribute '" + LOG_PROPERTY + "'");
|
||||||
|
}
|
||||||
String specifiedClass = (String) getAttribute(LOG_PROPERTY);
|
String specifiedClass = (String) getAttribute(LOG_PROPERTY);
|
||||||
|
|
||||||
if (specifiedClass == null) { // @deprecated
|
if (specifiedClass == null) { // @deprecated
|
||||||
logDiagnostic("Trying to get log class from attribute '" +
|
if (isDiagnosticsEnabled()) {
|
||||||
LOG_PROPERTY_OLD + "'");
|
logDiagnostic("Trying to get log class from attribute '" +
|
||||||
|
LOG_PROPERTY_OLD + "'");
|
||||||
|
}
|
||||||
specifiedClass = (String) getAttribute(LOG_PROPERTY_OLD);
|
specifiedClass = (String) getAttribute(LOG_PROPERTY_OLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specifiedClass == null) {
|
if (specifiedClass == null) {
|
||||||
logDiagnostic("Trying to get log class from system property '" +
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Trying to get log class from system property '" +
|
||||||
LOG_PROPERTY + "'");
|
LOG_PROPERTY + "'");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
specifiedClass = System.getProperty(LOG_PROPERTY);
|
specifiedClass = System.getProperty(LOG_PROPERTY);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
logDiagnostic("No access allowed to system property '" +
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("No access allowed to system property '" +
|
||||||
LOG_PROPERTY + "' - " + e.getMessage());
|
LOG_PROPERTY + "' - " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specifiedClass == null) { // @deprecated
|
if (specifiedClass == null) { // @deprecated
|
||||||
logDiagnostic("Trying to get log class from system property '" +
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Trying to get log class from system property '" +
|
||||||
LOG_PROPERTY_OLD + "'");
|
LOG_PROPERTY_OLD + "'");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
specifiedClass = System.getProperty(LOG_PROPERTY_OLD);
|
specifiedClass = System.getProperty(LOG_PROPERTY_OLD);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
logDiagnostic("No access allowed to system property '" +
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("No access allowed to system property '" +
|
||||||
LOG_PROPERTY_OLD + "' - " + e.getMessage());
|
LOG_PROPERTY_OLD + "' - " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,7 +926,9 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
boolean affectState)
|
boolean affectState)
|
||||||
throws LogConfigurationException {
|
throws LogConfigurationException {
|
||||||
|
|
||||||
logDiagnostic("Attempting to instantiate '" + logAdapterClassName + "'");
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Attempting to instantiate '" + logAdapterClassName + "'");
|
||||||
|
}
|
||||||
|
|
||||||
Object[] params = { logCategory };
|
Object[] params = { logCategory };
|
||||||
Log logAdapter = null;
|
Log logAdapter = null;
|
||||||
@@ -1149,10 +1186,12 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// UnifiedLoaderRepository) this can still work, so if user hasn't
|
// UnifiedLoaderRepository) this can still work, so if user hasn't
|
||||||
// forbidden it, just return the contextClassLoader.
|
// forbidden it, just return the contextClassLoader.
|
||||||
if (allowFlawedContext) {
|
if (allowFlawedContext) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Warning: the context classloader is not part of a"
|
logDiagnostic(
|
||||||
+ " parent-child relationship with the classloader that"
|
"Warning: the context classloader is not part of a"
|
||||||
+ " loaded LogFactoryImpl.");
|
+ " parent-child relationship with the classloader that"
|
||||||
|
+ " loaded LogFactoryImpl.");
|
||||||
|
}
|
||||||
// If contextClassLoader were null, getLowestClassLoader() would
|
// If contextClassLoader were null, getLowestClassLoader() would
|
||||||
// have returned thisClassLoader. The fact we are here means
|
// have returned thisClassLoader. The fact we are here means
|
||||||
// contextClassLoader is not null, so we can just return it.
|
// contextClassLoader is not null, so we can just return it.
|
||||||
@@ -1173,12 +1212,14 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// custom classloaders but fail to set the context classloader so
|
// custom classloaders but fail to set the context classloader so
|
||||||
// we handle those flawed systems anyway.
|
// we handle those flawed systems anyway.
|
||||||
if (allowFlawedContext) {
|
if (allowFlawedContext) {
|
||||||
logDiagnostic(
|
if (isDiagnosticsEnabled()) {
|
||||||
"Warning: the context classloader is an ancestor of the"
|
logDiagnostic(
|
||||||
+ " classloader that loaded LogFactoryImpl; it should be"
|
"Warning: the context classloader is an ancestor of the"
|
||||||
+ " the same or a descendant. The application using"
|
+ " classloader that loaded LogFactoryImpl; it should be"
|
||||||
+ " commons-logging should ensure the context classloader"
|
+ " the same or a descendant. The application using"
|
||||||
+ " is used correctly.");
|
+ " commons-logging should ensure the context classloader"
|
||||||
|
+ " is used correctly.");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new LogConfigurationException(
|
throw new LogConfigurationException(
|
||||||
"Bad classloader hierarchy; LogFactoryImpl was loaded via"
|
"Bad classloader hierarchy; LogFactoryImpl was loaded via"
|
||||||
@@ -1250,9 +1291,11 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
ClassLoader classLoader,
|
ClassLoader classLoader,
|
||||||
Throwable discoveryFlaw) {
|
Throwable discoveryFlaw) {
|
||||||
|
|
||||||
logDiagnostic("Could not instantiate Log '"
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Could not instantiate Log '"
|
||||||
+ logAdapterClassName + "' -- "
|
+ logAdapterClassName + "' -- "
|
||||||
+ discoveryFlaw.getLocalizedMessage());
|
+ discoveryFlaw.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
if (!allowFlawedDiscovery) {
|
if (!allowFlawedDiscovery) {
|
||||||
throw new LogConfigurationException(discoveryFlaw);
|
throw new LogConfigurationException(discoveryFlaw);
|
||||||
@@ -1326,17 +1369,20 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
msg.append("You have more than one version of ");
|
msg.append("You have more than one version of ");
|
||||||
msg.append(Log.class.getName());
|
msg.append(Log.class.getName());
|
||||||
msg.append(" visible.");
|
msg.append(" visible.");
|
||||||
logDiagnostic(msg.toString());
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic(msg.toString());
|
||||||
|
}
|
||||||
throw new LogConfigurationException(msg.toString());
|
throw new LogConfigurationException(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer msg = new StringBuffer();
|
if (isDiagnosticsEnabled()) {
|
||||||
msg.append("Warning: bad log hierarchy. ");
|
StringBuffer msg = new StringBuffer();
|
||||||
msg.append("You have more than one version of ");
|
msg.append("Warning: bad log hierarchy. ");
|
||||||
msg.append(Log.class.getName());
|
msg.append("You have more than one version of ");
|
||||||
msg.append(" visible.");
|
msg.append(Log.class.getName());
|
||||||
logDiagnostic(msg.toString());
|
msg.append(" visible.");
|
||||||
|
logDiagnostic(msg.toString());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// this is just a bad adapter class
|
// this is just a bad adapter class
|
||||||
if (!allowFlawedDiscovery) {
|
if (!allowFlawedDiscovery) {
|
||||||
@@ -1345,16 +1391,20 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
msg.append("Log class ");
|
msg.append("Log class ");
|
||||||
msg.append(badClass.getName());
|
msg.append(badClass.getName());
|
||||||
msg.append(" does not implement the Log interface.");
|
msg.append(" does not implement the Log interface.");
|
||||||
logDiagnostic(msg.toString());
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic(msg.toString());
|
||||||
|
}
|
||||||
|
|
||||||
throw new LogConfigurationException(msg.toString());
|
throw new LogConfigurationException(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer msg = new StringBuffer();
|
if (isDiagnosticsEnabled()) {
|
||||||
msg.append("Warning: Log class ");
|
StringBuffer msg = new StringBuffer();
|
||||||
msg.append(badClass.getName());
|
msg.append("Warning: Log class ");
|
||||||
msg.append(" does not implement the Log interface.");
|
msg.append(badClass.getName());
|
||||||
logDiagnostic(msg.toString());
|
msg.append(" does not implement the Log interface.");
|
||||||
|
logDiagnostic(msg.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user