logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: logging-log4j/src/java/org/apache/log4j PropertyConfigurator.java Layout.java AppenderSkeleton.java Appender.java
Date Tue, 28 Dec 2004 18:25:57 GMT
ceki        2004/12/28 10:25:57

  Modified:    src/java/org/apache/log4j PropertyConfigurator.java
                        Layout.java AppenderSkeleton.java Appender.java
  Log:
  Let Appenders and Layouts know about the LoggerRepository where they are attached
  
  Revision  Changes    Path
  1.77      +2 -1      logging-log4j/src/java/org/apache/log4j/PropertyConfigurator.java
  
  Index: PropertyConfigurator.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/PropertyConfigurator.java,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- PropertyConfigurator.java	14 Dec 2004 21:11:04 -0000	1.76
  +++ PropertyConfigurator.java	28 Dec 2004 18:25:57 -0000	1.77
  @@ -674,7 +674,7 @@
       }
   
       appender.setName(appenderName);
  -
  +    appender.setLoggerRepository(repository);
       if (appender instanceof OptionHandler) {
         String layoutClassName =
           OptionConverter.findAndSubst(layoutPrefix, props);
  @@ -687,6 +687,7 @@
               layoutClassName.trim(), Layout.class, null);
   
           if (layout != null) {
  +          layout.setLoggerRepository(repository);
             appender.setLayout(layout);
             getLogger(repository).debug(
               "Parsing layout options for \"" + appenderName + "\".");
  
  
  
  1.12      +35 -1     logging-log4j/src/java/org/apache/log4j/Layout.java
  
  Index: Layout.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/Layout.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Layout.java	3 Jun 2004 21:57:09 -0000	1.11
  +++ Layout.java	28 Dec 2004 18:25:57 -0000	1.12
  @@ -20,6 +20,7 @@
   import java.io.IOException;
   import java.io.Writer;
   
  +import org.apache.log4j.spi.LoggerRepository;
   import org.apache.log4j.spi.LoggingEvent;
   import org.apache.log4j.spi.OptionHandler;
   
  @@ -45,6 +46,7 @@
     String header;
     String footer;
   
  +  LoggerRepository repository;
     // Most layouts ignore the throwable. If a subclasses needs to override the 
     // default value it should do so in its default constructor.
     protected boolean ignoresThrowable = true;
  @@ -99,7 +101,7 @@
      * org.apache.log4j.xml.XMLLayout} returns <code>false</code>.
      * 
      * <p>As of log4j version 1.3, ignoresThrowable is a settable property. Thus,
  -   * you can override, a layout's default setting.
  +   * you can override a layout's default setting.
      * 
      * @since 0.8.4 
      * */
  @@ -137,5 +139,37 @@
      */
     public void setHeader(String header) {
       this.header = header;
  +  }
  +  
  +  /**
  +   * Repository where this layout is attached. If not set, the
  +   * returned valyue may be null.
  +   * 
  +   * @return The repository where this layout is attached.
  +   */
  +  public LoggerRepository getLoggerRepository() {
  +    return repository;
  +  }
  +    
  +  /**
  +   * Set the LoggerRepository this layout is attached to indirectly through its 
  +   * containing appener. This operation can only be performed once. Once set, 
  +   * the repository cannot be changed.
  +   *   
  +   * @param repository The repository where this layout is indirectly attached.
  +   * @throws IllegalStateException If you try to change the repository after it
  +   * has been set.
  +   * 
  +   * @since 1.3
  +   */
  +  public void setLoggerRepository(LoggerRepository repository) throws IllegalStateException
{
  +    if(repository == null) {
  +      throw new IllegalArgumentException("repository argument cannot be null");
  +    }
  +    if(this.repository != null) {
  +      this.repository = repository;
  +    } else {
  +      throw new IllegalStateException("Repository has been already set");
  +    }
     }
   }
  
  
  
  1.31      +30 -0     logging-log4j/src/java/org/apache/log4j/AppenderSkeleton.java
  
  Index: AppenderSkeleton.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/AppenderSkeleton.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- AppenderSkeleton.java	20 Nov 2004 13:15:58 -0000	1.30
  +++ AppenderSkeleton.java	28 Dec 2004 18:25:57 -0000	1.31
  @@ -20,6 +20,7 @@
   import org.apache.log4j.helpers.OnlyOnceErrorHandler;
   import org.apache.log4j.spi.ErrorHandler;
   import org.apache.log4j.spi.Filter;
  +import org.apache.log4j.spi.LoggerRepository;
   import org.apache.log4j.spi.LoggingEvent;
   import org.apache.log4j.spi.OptionHandler;
   
  @@ -83,6 +84,9 @@
      */
     private boolean guard = false;
   
  +  
  +  private LoggerRepository repository;
  +  
     /**
      * Derived appenders should override this method if option structure
      * requires it.
  @@ -309,5 +313,31 @@
         logger = LogManager.getLogger(this.getClass().getName());
       }
       return logger;
  +  }
  +  
  +  /**
  +   * Returns the repository where this appender is attached. If not set, the
  +   * returned valyue may be null.
  +   * 
  +   * @return The repository where this appender is attached.
  +   * @since 1.3
  +   */
  +  protected LoggerRepository getLoggerRepository() {
  +    return repository;
  +  }
  +  
  +
  +  /**
  +   * @see Appender#setLoggerRepository(LoggerRepository)
  +   */
  +  public void setLoggerRepository(LoggerRepository repository) throws IllegalStateException
{
  +    if(repository == null) {
  +      throw new IllegalArgumentException("repository argument cannot be null");
  +    }
  +    if(this.repository != null) {
  +      this.repository = repository;
  +    } else {
  +      throw new IllegalStateException("Repository has been already set");
  +    }
     }
   }
  
  
  
  1.14      +13 -0     logging-log4j/src/java/org/apache/log4j/Appender.java
  
  Index: Appender.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/Appender.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Appender.java	15 Nov 2004 17:31:07 -0000	1.13
  +++ Appender.java	28 Dec 2004 18:25:57 -0000	1.14
  @@ -18,6 +18,7 @@
   
   import org.apache.log4j.spi.ErrorHandler;
   import org.apache.log4j.spi.Filter;
  +import org.apache.log4j.spi.LoggerRepository;
   import org.apache.log4j.spi.LoggingEvent;
   
   
  @@ -111,5 +112,17 @@
      * @since 0.8.1
      */
     public void setName(String name);
  +  
  +
  +  /** 
  +   * Set the LoggerRepository this appender is attached to. This operation can
  +   * only be performed once. Once set, the repository cannot be changed.
  +   *   
  +   * @param repository The repository where this appender is attached.
  +   * @throws IllegalStateException If you try to change the repository after it
  +   * has been set.
  +   * @since 1.3
  +   **/
  +  public void setLoggerRepository(LoggerRepository repository) throws IllegalStateException;
     
   }
  
  
  

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


Mime
View raw message