commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsi...@apache.org
Subject cvs commit: jakarta-commons/logging/src/java/org/apache/commons/logging LogFactory.java
Date Sat, 19 Oct 2002 17:25:18 GMT
rsitze      2002/10/19 10:25:18

  Modified:    logging/src/java/org/apache/commons/logging LogFactory.java
  Log:
  - code cleanup, refactoring, and corrected a few undiscoved bugs..
  - Bugzilla 13157 - Log4j takes undue precedence over Log override.
  
  Revision  Changes    Path
  1.14      +47 -36    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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- LogFactory.java	17 Oct 2002 23:00:04 -0000	1.13
  +++ LogFactory.java	19 Oct 2002 17:25:18 -0000	1.14
  @@ -79,13 +79,14 @@
    * <p>Factory for creating {@link Log} instances, with discovery and
    * configuration features similar to that employed by standard Java APIs
    * such as JAXP.</p>
  - *
  + * 
    * <p><strong>IMPLEMENTATION NOTE</strong> - This implementation is heavily
    * based on the SAXParserFactory and DocumentBuilderFactory implementations
    * (corresponding to the JAXP pluggability APIs) found in Apache Xerces.</p>
    *
    * @author Craig R. McClanahan
    * @author Costin Manolache
  + * @author Richard A. Sitze
    * @version $Revision$ $Date$
    */
   
  @@ -102,7 +103,6 @@
       public static final String FACTORY_PROPERTY =
           "org.apache.commons.logging.LogFactory";
   
  -
       /**
        * The fully qualified class name of the fallback <code>LogFactory</code>
        * implementation class to use, if no other can be found.
  @@ -110,7 +110,6 @@
       public static final String FACTORY_DEFAULT =
           "org.apache.commons.logging.impl.LogFactoryImpl";
   
  -
       /**
        * The name of the properties file to search for.
        */
  @@ -239,9 +238,10 @@
        * <ul>
        * <li>The <code>org.apache.commons.logging.LogFactory</code> system
        *     property.</li>
  +     * <li>The JDK 1.3 Service Discovery mechanism</li>
        * <li>Use the properties file <code>commons-logging.properties</code>
        *     file, if found in the class path of this class.  The configuration
  -     *     file is in standard <code>java.util.Propertis</code> format and
  +     *     file is in standard <code>java.util.Properties</code> format and
        *     contains the fully qualified name of the implementation class
        *     with the key being the system property defined above.</li>
        * <li>Fall back to a default implementation class
  @@ -272,6 +272,25 @@
           if (factory != null)
               return factory;
   
  +
  +        // Load properties file..
  +        // will be used one way or another in the end.
  +
  +        Properties props=null;
  +        try {
  +            InputStream stream = (contextClassLoader == null
  +                                 ? ClassLoader.getSystemResourceAsStream( FACTORY_PROPERTIES
)
  +                                 : contextClassLoader.getResourceAsStream( FACTORY_PROPERTIES
));
  +            if (stream != null) {
  +                props = new Properties();
  +                props.load(stream);
  +                stream.close();
  +            }
  +        } catch (IOException e) {
  +        } catch (SecurityException e) {
  +        }
  +
  +        
           // First, try the system property
           try {
               String factoryClass = System.getProperty(FACTORY_PROPERTY);
  @@ -282,6 +301,7 @@
               ;  // ignore
           }
   
  +
           // Second, try to find a service by using the JDK1.3 jar
           // discovery mechanism. This will allow users to plug a logger
           // by just placing it in the lib/ directory of the webapp ( or in
  @@ -319,8 +339,6 @@
           }
   
   
  -        Properties props=null;
  -        
           // Third try a properties file. 
           // If the properties file exists, it'll be read and the properties
           // used. IMHO ( costin ) System property and JDK1.3 jar service
  @@ -329,28 +347,16 @@
           // the webapp, even if a default logger is set at JVM level by a
           // system property )
   
  -        try {
  -            InputStream stream = (contextClassLoader == null
  -                                 ? ClassLoader.getSystemResourceAsStream( FACTORY_PROPERTIES
)
  -                                 : contextClassLoader.getResourceAsStream( FACTORY_PROPERTIES
));
  -            if (stream != null) {
  -                props = new Properties();
  -                props.load(stream);
  -                stream.close();
  -                String factoryClass = props.getProperty(FACTORY_PROPERTY);
  -                if( factory==null ) {
  -                    if (factoryClass == null) {
  -                        factoryClass = FACTORY_DEFAULT;
  -                    }
  -                    factory = newFactory(factoryClass, contextClassLoader);
  -                }
  +        if (factory == null  &&  props != null) {
  +            String factoryClass = props.getProperty(FACTORY_PROPERTY);
  +            if (factoryClass != null) {
  +                factory = newFactory(factoryClass, contextClassLoader);
               }
  -            // the properties will be set at the end.
  -        } catch (IOException e) {
  -        } catch (SecurityException e) {
           }
   
  +
           // Fourth, try the fallback implementation class
  +
           if (factory == null) {
               factory = newFactory(FACTORY_DEFAULT, LogFactory.class.getClassLoader());
           }
  @@ -360,14 +366,14 @@
                * Always cache using context class loader..
                */
               cacheFactory(contextClassLoader, factory);
  -        }
   
  -        if( props!=null ) {
  -            Enumeration names = props.propertyNames();
  -            while (names.hasMoreElements()) {
  -                String name = (String) names.nextElement();
  -                String value = props.getProperty(name);
  -                factory.setAttribute(name, value);
  +            if( props!=null ) {
  +                Enumeration names = props.propertyNames();
  +                while (names.hasMoreElements()) {
  +                    String name = (String) names.nextElement();
  +                    String value = props.getProperty(name);
  +                    factory.setAttribute(name, value);
  +                }
               }
           }
           
  @@ -534,12 +540,17 @@
       {
           
           try {
  -            Class clazz = null;
               if (classLoader != null) {
                   try {
                       // first the given class loader param (thread class loader)
                       return (LogFactory)classLoader.loadClass(factoryClass).newInstance();
                   } catch (ClassNotFoundException ex) {
  +                    if (classLoader == LogFactory.class.getClassLoader()) {
  +                        // Nothing more to try, onwards.
  +                        throw ex;
  +                    }
  +                    // ignore exception, continue
  +                } catch (NoClassDefFoundError e) {
                       if (classLoader == LogFactory.class.getClassLoader()) {
                           // Nothing more to try, onwards.
                           throw ex;
  
  
  

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


Mime
View raw message