commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-commons/logging/src/java/org/apache/commons/logging/impl LogFactoryImpl.java
Date Fri, 15 Feb 2002 05:42:35 GMT
costin      02/02/14 21:42:35

  Modified:    logging/src/java/org/apache/commons/logging/impl
                        LogFactoryImpl.java
  Log:
  Add a mechanism to use a proxy. The default impl will first look for
  a logger package, and preferably use a specialized factory, which
  can provide better integration with the real logger.
  
  The introspection is ok, but it's limited and complex.
  
  Also, switch to SimpleLog by default - which is almost the same as
  using System.err.println(). If common logging requires the user to set
  properties and configurations to get the same behavior as System.err(),
  why would anyone use it ?
  
  Revision  Changes    Path
  1.4       +43 -12    jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java
  
  Index: LogFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LogFactoryImpl.java	14 Feb 2002 03:48:44 -0000	1.3
  +++ LogFactoryImpl.java	15 Feb 2002 05:42:35 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v
1.3 2002/02/14 03:48:44 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/02/14 03:48:44 $
  + * $Header: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v
1.4 2002/02/15 05:42:35 costin Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/15 05:42:35 $
    *
    * ====================================================================
    *
  @@ -104,12 +104,11 @@
    *
    * @author Rod Waldhoff
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2002/02/14 03:48:44 $
  + * @version $Revision: 1.4 $ $Date: 2002/02/15 05:42:35 $
    */
   
   public class LogFactoryImpl extends LogFactory {
   
  -
       // ----------------------------------------------------------- Constructors
   
   
  @@ -117,20 +116,22 @@
        * Public no-arguments constructor required by the lookup mechanism.
        */
       public LogFactoryImpl() {
  -
           super();
  -
  +        guessConfig();
       }
   
   
       // ----------------------------------------------------- Manifest Constants
   
   
  +    // Defaulting to NullLogger means important messages will be lost if
  +    // no other logger is available. This is as bad as having a catch() and
  +    // ignoring the exception because 'it can't happen'
       /**
        * The fully qualified name of the default {@link Log} implementation.
        */
       public static final String LOG_DEFAULT =
  -        "org.apache.commons.logging.impl.NoOpLog";
  +        "org.apache.commons.logging.impl.SimpleLog";
   
   
       /**
  @@ -173,6 +174,8 @@
       protected Constructor logConstructor = null;
   
   
  +    protected LogFactory proxyFactory=null;
  +
       /**
        * The signature of the Constructor to be used.
        */
  @@ -204,7 +207,8 @@
        * @param name Name of the attribute to return
        */
       public Object getAttribute(String name) {
  -
  +        if( proxyFactory != null )
  +            return proxyFactory.getAttribute( name );
           return (attributes.get(name));
   
       }
  @@ -216,6 +220,8 @@
        * length array is returned.
        */
       public String[] getAttributeNames() {
  +        if( proxyFactory != null )
  +            return proxyFactory.getAttributeNames();
   
           Vector names = new Vector();
           Enumeration keys = attributes.keys();
  @@ -241,7 +247,10 @@
        *  instance cannot be returned
        */
       public Log getInstance(Class clazz)
  -        throws LogConfigurationException {
  +        throws LogConfigurationException
  +    {
  +        if( proxyFactory != null )
  +            return proxyFactory.getInstance(clazz);
   
           return (getInstance(clazz.getName()));
   
  @@ -266,7 +275,10 @@
        *  instance cannot be returned
        */
       public Log getInstance(String name)
  -        throws LogConfigurationException {
  +        throws LogConfigurationException
  +    {
  +        if( proxyFactory != null )
  +            return proxyFactory.getInstance(name);
   
           Log instance = (Log) instances.get(name);
           if (instance == null) {
  @@ -286,6 +298,8 @@
        * class loader would prevent garbage collection.
        */
       public void release() {
  +        if( proxyFactory != null )
  +            proxyFactory.release();
   
           instances.clear();
   
  @@ -299,9 +313,10 @@
        * @param name Name of the attribute to remove
        */
       public void removeAttribute(String name) {
  +        if( proxyFactory != null )
  +            proxyFactory.removeAttribute(name);
   
           attributes.remove(name);
  -
       }
   
   
  @@ -315,6 +330,8 @@
        *  to remove any setting for this attribute
        */
       public void setAttribute(String name, Object value) {
  +        if( proxyFactory != null )
  +            proxyFactory.setAttribute(name,value);
   
           if (value == null) {
               attributes.remove(name);
  @@ -406,6 +423,20 @@
   
       }
   
  +    protected void guessConfig() {
  +        if( isLog4JAvailable() ) {
  +            try {
  +                Class proxyClass=findClassLoader().
  +                    loadClass( "org.apache.commons.logging.Log4jFactory" );
  +                proxyFactory=(LogFactory)proxyClass.newInstance();
  +            } catch( Throwable t ) {
  +                proxyFactory=null;
  +            }
  +        }
  +        // other logger specific initialization
  +        // ...
  +    }
  +    
   
       /**
        * Is <em>JDK 1.4 or later</em> logging available?
  
  
  

--
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