ceki        2004/11/19 07:19:07

  Modified:    src/java/org/apache/log4j/spi LoggerRepository.java
                        RootLogger.java
               src/java/org/apache/log4j Hierarchy.java
  Added:       src/java/org/apache/log4j/spi ErrorItem.java
  Removed:     src/java/org/apache/log4j/config ErrorItem.java
  Log:
  - Added getErrorList and addErrorItem(ErrorItem) methods to LoggerRepository 
intergace
  - Moved o.a.l.config.ErrorItem to o.a.l.spi.ErrorItem
  
  Revision  Changes    Path
  1.20      +12 -0     
logging-log4j/src/java/org/apache/log4j/spi/LoggerRepository.java
  
  Index: LoggerRepository.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggerRepository.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- LoggerRepository.java     28 Oct 2004 12:54:32 -0000      1.19
  +++ LoggerRepository.java     19 Nov 2004 15:19:07 -0000      1.20
  @@ -20,6 +20,7 @@
   import org.apache.log4j.plugins.PluginRegistry;
   
   import java.util.Enumeration;
  +import java.util.List;
   import java.util.Map;
   
   
  @@ -198,4 +199,15 @@
      */
     public void setProperty(String key, String value);
     
  +  /**
  +   * Errors which cannot be logged, go to the error list,
  +   * @return List
  +   */
  +  public List getErrorList();
  +
  +  /**
  +   * Errors which cannot be logged, go to the error list,
  +   * @return List
  +   */
  +  public void addErrorItem(ErrorItem errorItem);
   }
  
  
  
  1.2       +5 -3      
logging-log4j/src/java/org/apache/log4j/spi/RootLogger.java
  
  Index: RootLogger.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/spi/RootLogger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RootLogger.java   15 May 2004 18:22:57 -0000      1.1
  +++ RootLogger.java   19 Nov 2004 15:19:07 -0000      1.2
  @@ -17,7 +17,6 @@
   package org.apache.log4j.spi;
   
   import org.apache.log4j.*;
  -import org.apache.log4j.helpers.LogLog;
   
   
   // Contibutors: Mathias Bogaert
  @@ -59,8 +58,11 @@
        @since 0.8.3 */
     public final void setLevel(Level level) {
       if (level == null) {
  -      LogLog.error(
  -        "You have tried to set a null level to root.", new Throwable());
  +      if(repository != null) {
  +        repository.addErrorItem(new ErrorItem("You have tried to set a null 
level to root.", new Exception()));
  +      } else {
  +        throw new IllegalStateException("LoggerRepository has not been set");
  +      }
       } else {
         this.level = level;
       }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/spi/ErrorItem.java
  
  Index: ErrorItem.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.spi;
  
  /**
   * Used to store special log4j errors which cannot be logged using internal
   * logging. Such errors include thos occuring during the initial phases
   * of log4j configuration or errors emanating from core components such as
   * Logger or Hierarchy.
   * 
   * @author Ceki Gulcu
   */
  public class ErrorItem {
    String message;
    int colNumber = -1;
    int lineNumber = -1;
    Throwable exception;
  
    public ErrorItem(String message, Exception e) {
      this.message = message;
      exception = e;
    }
  
    public ErrorItem(String message) {
      this(message, null);
    }
  
    public int getColNumber() {
      return colNumber;
    }
  
    public void setColNumber(int colNumber) {
      this.colNumber = colNumber;
    }
  
    public Throwable getException() {
      return exception;
    }
  
    public void setException(Throwable exception) {
      this.exception = exception;
    }
  
    public int getLineNumber() {
      return lineNumber;
    }
  
    public void setLineNumber(int lineNumber) {
      this.lineNumber = lineNumber;
    }
  
    public String getMessage() {
      return message;
    }
  
    public void setMessage(String message) {
      this.message = message;
    }
  
    public String toString() {
      String str =
        "Reported error: \"" + message + "\" at line " + lineNumber + " column "
        + colNumber;
  
      if (exception != null) {
        str += (" with exception " + exception);
      }
      return str;
    }
  }
  
  
  
  1.55      +19 -0     logging-log4j/src/java/org/apache/log4j/Hierarchy.java
  
  Index: Hierarchy.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/Hierarchy.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Hierarchy.java    17 Nov 2004 21:25:23 -0000      1.54
  +++ Hierarchy.java    19 Nov 2004 15:19:07 -0000      1.55
  @@ -25,6 +25,7 @@
   import org.apache.log4j.or.ObjectRenderer;
   import org.apache.log4j.or.RendererMap;
   import org.apache.log4j.plugins.PluginRegistry;
  +import org.apache.log4j.spi.ErrorItem;
   import org.apache.log4j.spi.LoggerEventListener;
   import org.apache.log4j.spi.LoggerFactory;
   import org.apache.log4j.spi.LoggerRepository;
  @@ -34,6 +35,7 @@
   import java.util.ArrayList;
   import java.util.Enumeration;
   import java.util.Hashtable;
  +import java.util.List;
   import java.util.Map;
   import java.util.Vector;
   
  @@ -82,6 +84,8 @@
     // the internal logger used by this instance of Hierarchy for its own 
reporting
     private Logger myLogger;
     
  +  private List errorList = new Vector();
  +  
     boolean emittedNoAppenderWarning = false;
     boolean emittedNoResourceBundleWarning = false;
     boolean pristine = true;
  @@ -492,6 +496,21 @@
       return v.elements();
     }
   
  +  /**
  +   * Return the the list of previously encoutered [EMAIL PROTECTED] 
ErrorItem error items}.
  +   */
  +  public List getErrorList() {
  +    return errorList;
  +  }
  +  
  +  /**
  +   * Add an error item to the list of previously encountered errors.
  +   * @since 1.3 
  +   */
  +  public void addErrorItem(ErrorItem errorItem) {
  +    getErrorList().add(errorItem);
  +  }
  +  
     /**
        @deprecated Please use [EMAIL PROTECTED] #getCurrentLoggers} instead.
      */
  
  
  

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

Reply via email to