ceki        2004/03/26 00:14:59

  Modified:    src/java/org/apache/log4j/spi DefaultRepositorySelector.java
                        RepositorySelector.java
               src/java/org/apache/log4j/selector ContextJNDISelector.java
  Log:
  

  Added a remove() method to the RepositorySelector interface.
  
  Revision  Changes    Path
  1.6       +4 -0      
logging-log4j/src/java/org/apache/log4j/spi/DefaultRepositorySelector.java
  
  Index: DefaultRepositorySelector.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/spi/DefaultRepositorySelector.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultRepositorySelector.java    27 Feb 2004 16:47:34 -0000      1.5
  +++ DefaultRepositorySelector.java    26 Mar 2004 08:14:58 -0000      1.6
  @@ -33,4 +33,8 @@
          throw new IllegalStateException("default repository already set.");
       }
     }
  +  
  +  public void remove(String contextName) {
  +    // do nothing as the default reposiory cannot be removed
  +  }
   }
  
  
  
  1.8       +13 -0     
logging-log4j/src/java/org/apache/log4j/spi/RepositorySelector.java
  
  Index: RepositorySelector.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/spi/RepositorySelector.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RepositorySelector.java   27 Feb 2004 16:47:34 -0000      1.7
  +++ RepositorySelector.java   26 Mar 2004 08:14:58 -0000      1.8
  @@ -46,4 +46,17 @@
      * @since 1.3
      */
     public void setDefaultRepository(LoggerRepository def);
  +  
  +  /**
  +   * Remove the repository with the given context name from the list maintained
  +   * by the respository selector.
  +   * 
  +   * When applications are stopped or recycled, this method should be called to
  +   * ensure that the associated repostiroy is recycled as well.
  +   * 
  +   * If more than one application share the same logging context, then the
  +   * applications need to coordinate their actions.  
  +   * 
  +   */
  +  public void remove(String contextName);
   }
  
  
  
  1.7       +28 -7     
logging-log4j/src/java/org/apache/log4j/selector/ContextJNDISelector.java
  
  Index: ContextJNDISelector.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/selector/ContextJNDISelector.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContextJNDISelector.java  24 Mar 2004 19:32:54 -0000      1.6
  +++ ContextJNDISelector.java  26 Mar 2004 08:14:59 -0000      1.7
  @@ -21,6 +21,7 @@
   import org.apache.log4j.helpers.Constants;
   import org.apache.log4j.helpers.IntializationUtil;
   import org.apache.log4j.helpers.Loader;
  +import org.apache.log4j.helpers.LogLog;
   
   import org.apache.log4j.spi.LoggerRepository;
   import org.apache.log4j.spi.RepositorySelector;
  @@ -69,15 +70,19 @@
    * <blockquote>
    * <pre>
    * &lt;env-entry&gt;
  - *   &lt;description&gt;JNDI logging context for this app&lt;/description&gt;
  + *   &lt;description&gt;JNDI logging context name for this app&lt;/description&gt;
    *   &lt;env-entry-name&gt;log4j/context-name&lt;/env-entry-name&gt;
  - *   &lt;env-entry-value&gt;uniqueLoggingContextName&lt;/env-entry-value&gt;
  + *   &lt;env-entry-value&gt;aDistinctiveLoggingContextName&lt;/env-entry-value&gt;
    *   &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;
    * &lt;/env-entry&gt;
    * </pre>
    * </blockquote>
    * </p>
    *
  + * <p> If multiple applications have the same logging context name, then they 
  + * will share the same logging context. 
  + * </p>
  + * 
    *<p>You can also specify the URL for this context's configuration resource.
    * This repository selector (ContextJNDISelector) will use the specified resource
    * to automatically configure the log4j repository.
  @@ -92,14 +97,22 @@
    * &lt;/env-entry&gt;
    * </pre>
    * </blockquote>
  - *
  - *
  + * 
  + * <p>In case no configuration resource is specified, this repository selector
  + * will attempt to find the files <em>log4j.xml</em> and 
  + * <em>log4j.properties</em> from the resources available to the application.
  + * </p>
  + * 
  + * <p>It follows that bundling a <em>log4j.xml</em> file in your web-application
  + * and setting context name will be enough to ensure a separate logging 
  + * environment for your applicaiton.
  + *  
    * <p>Unlike the [EMAIL PROTECTED] ContextClassLoaderSelector} which will only work 
in
    * containers that provide for separate classloaders, JNDI is available in all
    * servers claiming to be servlet or J2EE compliant.  So, the JNDI selector
  - * may be the better choice.  However it is possible to spoof the value of the
  - * env-entry.  There are ways to avoid this, but this class makes no attempt
  - * to do so.  It would require a container specific implementation to,
  + * is the recommended context selector. However it is possible to spoof the 
  + * value of the env-entry.  There are ways to avoid this, but this class makes 
  + * no attempt to do so.  It would require a container specific implementation to,
    * for instance, append a non-random unique name to the user-defined value of
    * the env-entry.  Keep that in mind as you choose which custom repository
    * selector you would like to use in your own application.  Until this issue
  @@ -211,7 +224,15 @@
       try {
         return (String) ctx.lookup(name);
       } catch (NamingException e) {
  +      LogLog.warn("Failed to get "+name);
         return null;
       }
  +  }
  +  
  +  /** Remove the repository with the given context name from the list of
  +   * known repositories.
  +   */
  +  public void remove(String contextName) {
  +    hierMap.remove(contextName);  
     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to