Improve diagnostics
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@394467 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -20,6 +20,7 @@ package org.apache.commons.logging.impl;
|
|||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@@ -682,32 +683,41 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Trying to get configuration for item " + property);
|
logDiagnostic("[ENV] Trying to get configuration for item " + property);
|
||||||
}
|
}
|
||||||
if (isDiagnosticsEnabled()) {
|
|
||||||
logDiagnostic("[ENV] Looking for attribute " + property);
|
|
||||||
}
|
|
||||||
Object valueObj = getAttribute(property);
|
Object valueObj = getAttribute(property);
|
||||||
if (valueObj != null) {
|
if (valueObj != null) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Found value [" + valueObj + "] for " + property);
|
logDiagnostic("[ENV] Found LogFactory attribute [" + valueObj + "] for " + property);
|
||||||
}
|
}
|
||||||
return valueObj.toString();
|
return valueObj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Looking for system property " + property);
|
logDiagnostic("[ENV] No LogFactory attribute found for " + property);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String value = System.getProperty(property);
|
String value = System.getProperty(property);
|
||||||
|
if (value != null) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Found value [" + value + "] for " + property);
|
logDiagnostic("[ENV] Found system property [" + value + "] for " + property);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("[ENV] No system property found for property " + property);
|
||||||
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Security prevented reading system property.");
|
logDiagnostic("[ENV] Security prevented reading system property " + property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("[ENV] No configuration defined for item " + property);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,7 +759,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
throws LogConfigurationException
|
throws LogConfigurationException
|
||||||
{
|
{
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Attempting to discover a Log implementation...");
|
logDiagnostic("Discovering a Log implementation...");
|
||||||
}
|
}
|
||||||
|
|
||||||
initConfiguration();
|
initConfiguration();
|
||||||
@@ -760,6 +770,11 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
String specifiedLogClassName = findUserSpecifiedLogClassName();
|
String specifiedLogClassName = findUserSpecifiedLogClassName();
|
||||||
|
|
||||||
if (specifiedLogClassName != null) {
|
if (specifiedLogClassName != null) {
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic("Attempting to load user-specified log class '" +
|
||||||
|
specifiedLogClassName + "'...");
|
||||||
|
}
|
||||||
|
|
||||||
result = createLogFromClass(specifiedLogClassName,
|
result = createLogFromClass(specifiedLogClassName,
|
||||||
logCategory,
|
logCategory,
|
||||||
true);
|
true);
|
||||||
@@ -812,6 +827,11 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// service file in META-INF to force use of that logging lib anyway,
|
// service file in META-INF to force use of that logging lib anyway,
|
||||||
// rather than relying on discovery.
|
// rather than relying on discovery.
|
||||||
|
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
|
logDiagnostic(
|
||||||
|
"No user-specified Log implementation; performing discovery" +
|
||||||
|
" using the standard supported logging implementations...");
|
||||||
|
}
|
||||||
for(int i=0; (i<classesToDiscover.length) && (result == null); ++i) {
|
for(int i=0; (i<classesToDiscover.length) && (result == null); ++i) {
|
||||||
result = createLogFromClass(classesToDiscover[i], logCategory, true);
|
result = createLogFromClass(classesToDiscover[i], logCategory, true);
|
||||||
}
|
}
|
||||||
@@ -946,6 +966,35 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
+ "' from classloader "
|
+ "' from classloader "
|
||||||
+ objectId(currentCL));
|
+ objectId(currentCL));
|
||||||
try {
|
try {
|
||||||
|
if (isDiagnosticsEnabled()) {
|
||||||
|
// show exactly where we are loading this class from.
|
||||||
|
URL url;
|
||||||
|
String resourceName = logAdapterClassName.replace('.', '/') + ".class";
|
||||||
|
if (currentCL != null) {
|
||||||
|
url = currentCL.getResource(resourceName );
|
||||||
|
} else {
|
||||||
|
url = ClassLoader.getSystemResource(resourceName + ".class");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url == null) {
|
||||||
|
logDiagnostic("Class '" + logAdapterClassName + "' [" + resourceName + "] cannot be found.");
|
||||||
|
} else {
|
||||||
|
logDiagnostic("Class '" + logAdapterClassName + "' was found at '" + url + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hack
|
||||||
|
{
|
||||||
|
String l4jCategory = "org.apache.log4j.Category";
|
||||||
|
String l4jResource = l4jCategory.replace('.', '/') + ".class";
|
||||||
|
URL l4jUrl = currentCL.getResource(l4jResource);
|
||||||
|
if (l4jUrl == null) {
|
||||||
|
logDiagnostic("log4j not found:" + l4jResource);
|
||||||
|
} else {
|
||||||
|
logDiagnostic("log4j found:" + l4jUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Class c = null;
|
Class c = null;
|
||||||
try {
|
try {
|
||||||
c = Class.forName(logAdapterClassName, true, currentCL);
|
c = Class.forName(logAdapterClassName, true, currentCL);
|
||||||
|
|||||||
Reference in New Issue
Block a user