Improved error handling. Added custom message when the configured LogFactory implementation does not extend LogFactory. This should make it easier to diagnose when a user has made a mistake in the logging configuration, for example by setting LogFactory to a Log implementation.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138977 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogConfigurationException.java,v 1.2 2003/03/30 23:42:36 craigmcc Exp $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2003/03/30 23:42:36 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogConfigurationException.java,v 1.3 2003/05/01 10:32:36 rdonkin Exp $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2003/05/01 10:32:36 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
@@ -68,7 +68,7 @@ package org.apache.commons.logging;
|
||||
* factory methods.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision: 1.2 $ $Date: 2003/03/30 23:42:36 $
|
||||
* @version $Revision: 1.3 $ $Date: 2003/05/01 10:32:36 $
|
||||
*/
|
||||
|
||||
public class LogConfigurationException extends RuntimeException {
|
||||
@@ -117,7 +117,7 @@ public class LogConfigurationException extends RuntimeException {
|
||||
*/
|
||||
public LogConfigurationException(String message, Throwable cause) {
|
||||
|
||||
super(message);
|
||||
super(message + " (Caused by " + cause + ")");
|
||||
this.cause = cause; // Two-argument version requires JDK 1.4 or later
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogFactory.java,v 1.21 2003/03/30 23:42:36 craigmcc Exp $
|
||||
* $Revision: 1.21 $
|
||||
* $Date: 2003/03/30 23:42:36 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogFactory.java,v 1.22 2003/05/01 10:32:36 rdonkin Exp $
|
||||
* $Revision: 1.22 $
|
||||
* $Date: 2003/05/01 10:32:36 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
@@ -87,7 +87,7 @@ import java.util.Properties;
|
||||
* @author Craig R. McClanahan
|
||||
* @author Costin Manolache
|
||||
* @author Richard A. Sitze
|
||||
* @version $Revision: 1.21 $ $Date: 2003/03/30 23:42:36 $
|
||||
* @version $Revision: 1.22 $ $Date: 2003/05/01 10:32:36 $
|
||||
*/
|
||||
|
||||
public abstract class LogFactory {
|
||||
@@ -561,6 +561,9 @@ public abstract class LogFactory {
|
||||
Object result = AccessController.doPrivileged(
|
||||
new PrivilegedAction() {
|
||||
public Object run() {
|
||||
// This will be used to diagnose bad configurations
|
||||
// and allow a useful message to be sent to the user
|
||||
Class logFactoryClass = null;
|
||||
try {
|
||||
if (classLoader != null) {
|
||||
try {
|
||||
@@ -568,7 +571,9 @@ public abstract class LogFactory {
|
||||
|
||||
// warning: must typecast here & allow exception
|
||||
// to be generated/caught & recast propertly.
|
||||
return (LogFactory)classLoader.loadClass(factoryClass).newInstance();
|
||||
logFactoryClass = classLoader.loadClass(factoryClass);
|
||||
return (LogFactory) logFactoryClass.newInstance();
|
||||
|
||||
} catch (ClassNotFoundException ex) {
|
||||
if (classLoader == LogFactory.class.getClassLoader()) {
|
||||
// Nothing more to try, onwards.
|
||||
@@ -581,7 +586,7 @@ public abstract class LogFactory {
|
||||
throw e;
|
||||
}
|
||||
|
||||
}catch(ClassCastException e){
|
||||
} catch(ClassCastException e){
|
||||
|
||||
if (classLoader == LogFactory.class.getClassLoader()) {
|
||||
// Nothing more to try, onwards (bug in loader implementation).
|
||||
@@ -604,8 +609,17 @@ public abstract class LogFactory {
|
||||
*/
|
||||
// warning: must typecast here & allow exception
|
||||
// to be generated/caught & recast propertly.
|
||||
return (LogFactory)Class.forName(factoryClass).newInstance();
|
||||
logFactoryClass = Class.forName(factoryClass);
|
||||
return (LogFactory) logFactoryClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
// check to see if we've got a bad configuration
|
||||
if (logFactoryClass != null
|
||||
&& !LogFactory.class.isAssignableFrom(logFactoryClass)) {
|
||||
return new LogConfigurationException(
|
||||
"The chosen LogFactory implementation does not extend LogFactory."
|
||||
+ " Please check your configuration.",
|
||||
e);
|
||||
}
|
||||
return new LogConfigurationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user