Improved message issued when user specified log class cannot be loaded: when the name is close to that of one of the standard implementations, a hint is provided.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@376454 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -66,9 +66,21 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
|
|
||||||
public class LogFactoryImpl extends LogFactory {
|
public class LogFactoryImpl extends LogFactory {
|
||||||
|
|
||||||
|
|
||||||
|
/** Log4JLogger class name */
|
||||||
|
private static final String LOGGING_IMPL_LOG4J_LOGGER = "org.apache.commons.logging.impl.Log4JLogger";
|
||||||
|
/** Jdk14Logger class name */
|
||||||
|
private static final String LOGGING_IMPL_JDK14_LOGGER = "org.apache.commons.logging.impl.Jdk14Logger";
|
||||||
|
/** Jdk13LumberjackLogger class name */
|
||||||
|
private static final String LOGGING_IMPL_LUMBERJACK_LOGGER = "org.apache.commons.logging.impl.Jdk13LumberjackLogger";
|
||||||
|
/** SimpleLog class name */
|
||||||
|
private static final String LOGGING_IMPL_SIMPLE_LOGGER = "org.apache.commons.logging.impl.SimpleLog";
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------- Constructors
|
// ----------------------------------------------------------- Constructors
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public no-arguments constructor required by the lookup mechanism.
|
* Public no-arguments constructor required by the lookup mechanism.
|
||||||
*/
|
*/
|
||||||
@@ -149,7 +161,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* but broken/unusable for some reason.
|
* but broken/unusable for some reason.
|
||||||
*/
|
*/
|
||||||
private static final String[] classesToDiscover = {
|
private static final String[] classesToDiscover = {
|
||||||
"org.apache.commons.logging.impl.Log4JLogger",
|
LOGGING_IMPL_LOG4J_LOGGER,
|
||||||
"org.apache.commons.logging.impl.Jdk14Logger",
|
"org.apache.commons.logging.impl.Jdk14Logger",
|
||||||
"org.apache.commons.logging.impl.Jdk13LumberjackLogger",
|
"org.apache.commons.logging.impl.Jdk13LumberjackLogger",
|
||||||
"org.apache.commons.logging.impl.SimpleLog"
|
"org.apache.commons.logging.impl.SimpleLog"
|
||||||
@@ -546,7 +558,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
protected boolean isLog4JAvailable() {
|
protected boolean isLog4JAvailable() {
|
||||||
return isLogLibraryAvailable(
|
return isLogLibraryAvailable(
|
||||||
"Log4J",
|
"Log4J",
|
||||||
"org.apache.commons.logging.impl.Log4JLogger");
|
LOGGING_IMPL_LOG4J_LOGGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -714,9 +726,21 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
logCategory,
|
logCategory,
|
||||||
true);
|
true);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw new LogConfigurationException(
|
StringBuffer messageBuffer = new StringBuffer("User-specified log class '");
|
||||||
"User-specified log class '" + specifiedLogClassName
|
messageBuffer.append(specifiedLogClassName);
|
||||||
+ "' cannot be found or is not useable.");
|
messageBuffer.append("' cannot be found or is not useable.");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Mistyping or misspelling names is a common fault.
|
||||||
|
// Construct a good error message, if we can
|
||||||
|
if (specifiedLogClassName != null) {
|
||||||
|
final String trimmedName = specifiedLogClassName.trim();
|
||||||
|
informUponSimilarName(messageBuffer, trimmedName, LOGGING_IMPL_LOG4J_LOGGER);
|
||||||
|
informUponSimilarName(messageBuffer, trimmedName, LOGGING_IMPL_JDK14_LOGGER);
|
||||||
|
informUponSimilarName(messageBuffer, trimmedName, LOGGING_IMPL_LUMBERJACK_LOGGER);
|
||||||
|
informUponSimilarName(messageBuffer, trimmedName, LOGGING_IMPL_SIMPLE_LOGGER);
|
||||||
|
}
|
||||||
|
throw new LogConfigurationException(messageBuffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -763,6 +787,26 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends message if the given name is similar to the candidate.
|
||||||
|
* @param messageBuffer <code>StringBuffer</code> the message should be appended to,
|
||||||
|
* not null
|
||||||
|
* @param name the (trimmed) name to be test against the candidate, not null
|
||||||
|
* @param candidate the candidate name
|
||||||
|
*/
|
||||||
|
private void informUponSimilarName(final StringBuffer messageBuffer, final String name,
|
||||||
|
final String candidate) {
|
||||||
|
// this formular (first four letters of the name excluding package)
|
||||||
|
// gives a reason guess
|
||||||
|
if (candidate.regionMatches(true, 0, name, 0, 38)) {
|
||||||
|
messageBuffer.append(" Did you mean '");
|
||||||
|
messageBuffer.append(candidate);
|
||||||
|
messageBuffer.append("'?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks system properties and the attribute map for
|
* Checks system properties and the attribute map for
|
||||||
* a Log implementation specified by the user under the
|
* a Log implementation specified by the user under the
|
||||||
|
|||||||
Reference in New Issue
Block a user