Fix problem with "suggested" alternative for invalid log adapter class.
Always trim whitespace from user-specified log adapter class name. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@395181 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -77,6 +77,8 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
/** SimpleLog class name */
|
/** SimpleLog class name */
|
||||||
private static final String LOGGING_IMPL_SIMPLE_LOGGER = "org.apache.commons.logging.impl.SimpleLog";
|
private static final String LOGGING_IMPL_SIMPLE_LOGGER = "org.apache.commons.logging.impl.SimpleLog";
|
||||||
|
|
||||||
|
private static final String PKG_IMPL="org.apache.commons.logging.impl.";
|
||||||
|
private static final int PKG_LEN = PKG_IMPL.length();
|
||||||
|
|
||||||
// ----------------------------------------------------------- Constructors
|
// ----------------------------------------------------------- Constructors
|
||||||
|
|
||||||
@@ -783,15 +785,13 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
messageBuffer.append(specifiedLogClassName);
|
messageBuffer.append(specifiedLogClassName);
|
||||||
messageBuffer.append("' cannot be found or is not useable.");
|
messageBuffer.append("' cannot be found or is not useable.");
|
||||||
|
|
||||||
//
|
|
||||||
// Mistyping or misspelling names is a common fault.
|
// Mistyping or misspelling names is a common fault.
|
||||||
// Construct a good error message, if we can
|
// Construct a good error message, if we can
|
||||||
if (specifiedLogClassName != null) {
|
if (specifiedLogClassName != null) {
|
||||||
final String trimmedName = specifiedLogClassName.trim();
|
informUponSimilarName(messageBuffer, specifiedLogClassName, LOGGING_IMPL_LOG4J_LOGGER);
|
||||||
informUponSimilarName(messageBuffer, trimmedName, LOGGING_IMPL_LOG4J_LOGGER);
|
informUponSimilarName(messageBuffer, specifiedLogClassName, LOGGING_IMPL_JDK14_LOGGER);
|
||||||
informUponSimilarName(messageBuffer, trimmedName, LOGGING_IMPL_JDK14_LOGGER);
|
informUponSimilarName(messageBuffer, specifiedLogClassName, LOGGING_IMPL_LUMBERJACK_LOGGER);
|
||||||
informUponSimilarName(messageBuffer, trimmedName, LOGGING_IMPL_LUMBERJACK_LOGGER);
|
informUponSimilarName(messageBuffer, specifiedLogClassName, LOGGING_IMPL_SIMPLE_LOGGER);
|
||||||
informUponSimilarName(messageBuffer, trimmedName, LOGGING_IMPL_SIMPLE_LOGGER);
|
|
||||||
}
|
}
|
||||||
throw new LogConfigurationException(messageBuffer.toString());
|
throw new LogConfigurationException(messageBuffer.toString());
|
||||||
}
|
}
|
||||||
@@ -845,19 +845,25 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends message if the given name is similar to the candidate.
|
* Appends message if the given name is similar to the candidate.
|
||||||
* @param messageBuffer <code>StringBuffer</code> the message should be appended to,
|
* @param messageBuffer <code>StringBuffer</code> the message should be appended to,
|
||||||
* not null
|
* not null
|
||||||
* @param name the (trimmed) name to be test against the candidate, not null
|
* @param name the (trimmed) name to be test against the candidate, not null
|
||||||
* @param candidate the candidate name
|
* @param candidate the candidate name (not null)
|
||||||
*/
|
*/
|
||||||
private void informUponSimilarName(final StringBuffer messageBuffer, final String name,
|
private void informUponSimilarName(final StringBuffer messageBuffer, final String name,
|
||||||
final String candidate) {
|
final String candidate) {
|
||||||
// this formular (first four letters of the name excluding package)
|
if (name.equals(candidate)) {
|
||||||
// gives a reason guess
|
// Don't suggest a name that is exactly the same as the one the
|
||||||
if (candidate.regionMatches(true, 0, name, 0, 38)) {
|
// user tried...
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the user provides a name that is in the right package, and gets
|
||||||
|
// the first 4 characters of the adapter class right (ignoring case),
|
||||||
|
// then suggest the candidate adapter class name.
|
||||||
|
if (name.regionMatches(true, 0, candidate, 0, PKG_LEN + 4)) {
|
||||||
messageBuffer.append(" Did you mean '");
|
messageBuffer.append(" Did you mean '");
|
||||||
messageBuffer.append(candidate);
|
messageBuffer.append(candidate);
|
||||||
messageBuffer.append("'?");
|
messageBuffer.append("'?");
|
||||||
@@ -917,8 +923,14 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return specifiedClass;
|
// Remove any whitespace; it's never valid in a classname so its
|
||||||
|
// presence just means a user mistake. As we know what they meant,
|
||||||
|
// we may as well strip the spaces.
|
||||||
|
if (specifiedClass != null) {
|
||||||
|
specifiedClass = specifiedClass.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return specifiedClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user