You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2006/02/09 23:16:14 UTC
svn commit: r376454 -
/jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java
Author: rdonkin
Date: Thu Feb 9 14:16:12 2006
New Revision: 376454
URL: http://svn.apache.org/viewcvs?rev=376454&view=rev
Log:
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.
Modified:
jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java
Modified: jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java?rev=376454&r1=376453&r2=376454&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java (original)
+++ jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java Thu Feb 9 14:16:12 2006
@@ -66,8 +66,20 @@
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
+
/**
* Public no-arguments constructor required by the lookup mechanism.
@@ -149,7 +161,7 @@
* but broken/unusable for some reason.
*/
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.Jdk13LumberjackLogger",
"org.apache.commons.logging.impl.SimpleLog"
@@ -546,7 +558,7 @@
protected boolean isLog4JAvailable() {
return isLogLibraryAvailable(
"Log4J",
- "org.apache.commons.logging.impl.Log4JLogger");
+ LOGGING_IMPL_LOG4J_LOGGER);
}
@@ -714,9 +726,21 @@
logCategory,
true);
if (result == null) {
- throw new LogConfigurationException(
- "User-specified log class '" + specifiedLogClassName
- + "' cannot be found or is not useable.");
+ StringBuffer messageBuffer = new StringBuffer("User-specified log class '");
+ messageBuffer.append(specifiedLogClassName);
+ 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;
@@ -760,6 +784,26 @@
}
return result;
+ }
+
+
+
+ /**
+ * 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("'?");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org