commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/logging/src/java/org/apache/commons/logging LogConfigurationException.java LogFactory.java
Date Thu, 01 May 2003 10:32:37 GMT
rdonkin     2003/05/01 03:32:36

  Modified:    logging/src/java/org/apache/commons/logging
                        LogConfigurationException.java LogFactory.java
  Log:
  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.
  
  Revision  Changes    Path
  1.3       +5 -5      jakarta-commons/logging/src/java/org/apache/commons/logging/LogConfigurationException.java
  
  Index: LogConfigurationException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/LogConfigurationException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LogConfigurationException.java	30 Mar 2003 23:42:36 -0000	1.2
  +++ LogConfigurationException.java	1 May 2003 10:32:36 -0000	1.3
  @@ -117,7 +117,7 @@
        */
       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.22      +21 -7     jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java
  
  Index: LogFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- LogFactory.java	30 Mar 2003 23:42:36 -0000	1.21
  +++ LogFactory.java	1 May 2003 10:32:36 -0000	1.22
  @@ -561,6 +561,9 @@
           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 @@
                                   
                                   // 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 @@
                                       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 @@
                            */
                           // 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);
                       }
                   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message