ceki        01/07/30 12:30:05

  Modified:    src/java/org/apache/log4j Category.java Hierarchy.java
                        Priority.java PropertyConfigurator.java
               src/java/org/apache/log4j/test runAll
  Log:
  - The ALL and OFF priorities have been added to the Priority class.
  
  - The the disable familiy of methods in the Herarchy class have been deprecated.
    They are replaced with the enable familiy of methods. The negative logic of
    disable was somewhat confusing.
  
  - The "log4j.disableOverride" system property is no longer
    honoured. The sticky logic was just too complicated to maintain.
  
  Revision  Changes    Path
  1.38      +18 -18    jakarta-log4j/src/java/org/apache/log4j/Category.java
  
  Index: Category.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Category.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- Category.java     2001/07/25 19:43:43     1.37
  +++ Category.java     2001/07/30 19:30:04     1.38
  @@ -310,7 +310,7 @@
       @param message the message object to log. */
     public
     void debug(Object message) {
  -    if(hierarchy.disable >=  Priority.DEBUG_INT) 
  +    if(hierarchy.enableInt >  Priority.DEBUG_INT) 
         return;    
       if(Priority.DEBUG.isGreaterOrEqual(this.getChainedPriority())) {
         forcedLog(FQCN, Priority.DEBUG, message, null);
  @@ -329,7 +329,7 @@
      @param t the exception to log, including its stack trace.  */  
     public
     void debug(Object message, Throwable t) {
  -    if(hierarchy.disable >=  Priority.DEBUG_INT) 
  +    if(hierarchy.enableInt >  Priority.DEBUG_INT) 
         return;
       if(Priority.DEBUG.isGreaterOrEqual(this.getChainedPriority()))
         forcedLog(FQCN, Priority.DEBUG, message, t);    
  @@ -364,7 +364,7 @@
       @param message the message object to log */
     public
     void error(Object message) {
  -    if(hierarchy.disable >=  Priority.ERROR_INT) 
  +    if(hierarchy.enableInt >  Priority.ERROR_INT) 
         return;
       if(Priority.ERROR.isGreaterOrEqual(this.getChainedPriority()))
         forcedLog(FQCN, Priority.ERROR, message, null);
  @@ -381,7 +381,7 @@
      @param t the exception to log, including its stack trace.  */  
     public
     void error(Object message, Throwable t) {
  -    if(hierarchy.disable >=  Priority.ERROR_INT) 
  +    if(hierarchy.enableInt >  Priority.ERROR_INT) 
         return;
       if(Priority.ERROR.isGreaterOrEqual(this.getChainedPriority()))
         forcedLog(FQCN, Priority.ERROR, message, t);
  @@ -422,7 +422,7 @@
       @param message the message object to log */
     public
     void fatal(Object message) {
  -    if(hierarchy.disable >=  Priority.FATAL_INT) 
  +    if(hierarchy.enableInt >  Priority.FATAL_INT) 
         return;    
       if(Priority.FATAL.isGreaterOrEqual(this.getChainedPriority()))
         forcedLog(FQCN, Priority.FATAL, message, null);
  @@ -439,7 +439,7 @@
      @param t the exception to log, including its stack trace.  */
     public
     void fatal(Object message, Throwable t) {
  -    if(hierarchy.disable >=  Priority.FATAL_INT) 
  +    if(hierarchy.enableInt >  Priority.FATAL_INT) 
         return;   
       if(Priority.FATAL.isGreaterOrEqual(this.getChainedPriority()))
         forcedLog(FQCN, Priority.FATAL, message, t);
  @@ -708,7 +708,7 @@
       @param message the message object to log */
     public
     void info(Object message) {
  -    if(hierarchy.disable >=  Priority.INFO_INT) 
  +    if(hierarchy.enableInt >  Priority.INFO_INT) 
         return;    
       if(Priority.INFO.isGreaterOrEqual(this.getChainedPriority()))
         forcedLog(FQCN, Priority.INFO, message, null);
  @@ -725,7 +725,7 @@
      @param t the exception to log, including its stack trace.  */
     public
     void info(Object message, Throwable t) {
  -    if(hierarchy.disable >=  Priority.INFO_INT) 
  +    if(hierarchy.enableInt >  Priority.INFO_INT) 
         return;   
       if(Priority.INFO.isGreaterOrEqual(this.getChainedPriority()))
         forcedLog(FQCN, Priority.INFO, message, t);
  @@ -767,7 +767,7 @@
       *   */
     public
     boolean isDebugEnabled() {
  -    if(hierarchy.disable >=  Priority.DEBUG_INT)
  +    if(hierarchy.enableInt >  Priority.DEBUG_INT)
         return false;   
       return Priority.DEBUG.isGreaterOrEqual(this.getChainedPriority());
     }
  @@ -782,7 +782,7 @@
     */
     public
     boolean isEnabledFor(Priority priority) {
  -    if(hierarchy.disable >=  priority.level) 
  +    if(hierarchy.enableInt >  priority.level) 
         return false;
       return priority.isGreaterOrEqual(this.getChainedPriority());
     }
  @@ -796,7 +796,7 @@
     */
     public
     boolean isInfoEnabled() {
  -    if(hierarchy.disable >= Priority.INFO_INT)
  +    if(hierarchy.enableInt > Priority.INFO_INT)
         return false;   
       return Priority.INFO.isGreaterOrEqual(this.getChainedPriority());
     }
  @@ -812,7 +812,7 @@
        @since 0.8.4 */
     public
     void l7dlog(Priority priority, String key, Throwable t) {
  -    if(hierarchy.disable >= priority.level) {
  +    if(hierarchy.enableInt > priority.level) {
         return;
       }
       if(priority.isGreaterOrEqual(this.getChainedPriority())) {
  @@ -836,7 +836,7 @@
     */
     public
     void l7dlog(Priority priority, String key,  Object[] params, Throwable t) {
  -    if(hierarchy.disable >= priority.level) {
  +    if(hierarchy.enableInt > priority.level) {
         return;
       }    
       if(priority.isGreaterOrEqual(this.getChainedPriority())) {
  @@ -855,7 +855,7 @@
      */
     public
     void log(Priority priority, Object message, Throwable t) {
  -    if(hierarchy.disable >= priority.level) {
  +    if(hierarchy.enableInt > priority.level) {
         return;
       }
       if(priority.isGreaterOrEqual(this.getChainedPriority())) 
  @@ -867,7 +867,7 @@
    */
     public
     void log(Priority priority, Object message) {
  -    if(hierarchy.disable >= priority.level) {
  +    if(hierarchy.enableInt > priority.level) {
         return;
       }
       if(priority.isGreaterOrEqual(this.getChainedPriority()))
  @@ -885,7 +885,7 @@
        @param t The throwable of the logging request, may be null.  */
     public
     void log(String callerFQCN, Priority priority, Object message, Throwable t) {
  -    if(hierarchy.disable >= priority.level) {
  +    if(hierarchy.enableInt > priority.level) {
         return;
       }
       if(priority.isGreaterOrEqual(this.getChainedPriority())) {
  @@ -1018,7 +1018,7 @@
       @param message the message object to log.  */
     public
     void warn(Object message) {
  -    if(hierarchy.disable >=  Priority.WARN_INT) 
  +    if(hierarchy.enableInt >  Priority.WARN_INT) 
         return;   
   
       if(Priority.WARN.isGreaterOrEqual(this.getChainedPriority()))
  @@ -1036,7 +1036,7 @@
      @param t the exception to log, including its stack trace.  */
     public
     void warn(Object message, Throwable t) {
  -    if(hierarchy.disable >=  Priority.WARN_INT) 
  +    if(hierarchy.enableInt >  Priority.WARN_INT) 
         return;   
       if(Priority.WARN.isGreaterOrEqual(this.getChainedPriority()))
         forcedLog(FQCN, Priority.WARN, message, t);
  
  
  
  1.23      +51 -60    jakarta-log4j/src/java/org/apache/log4j/Hierarchy.java
  
  Index: Hierarchy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Hierarchy.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Hierarchy.java    2001/07/26 11:16:48     1.22
  +++ Hierarchy.java    2001/07/30 19:30:04     1.23
  @@ -55,11 +55,6 @@
   */
   public class Hierarchy {
   
  -  // DISABLE_OFF should be set to a value lower than all possible
  -  // priorities.
  -  static final int DISABLE_OFF = -1;
  -  static final int DISABLE_OVERRIDE = -2;  
  -  
     private CategoryFactory defaultFactory;
     private Vector listeners;
   
  @@ -67,7 +62,8 @@
     Category root;
     RendererMap rendererMap;
     
  -  int disable;
  +  int enableInt;
  +  Priority enable;
   
     boolean emittedNoAppenderWarning = false;
     boolean emittedNoResourceBundleWarning = false;  
  @@ -83,8 +79,8 @@
       ht = new Hashtable();
       listeners = new Vector(1);
       this.root = root;
  -    // Don't disable any priority level by default.
  -    disable = DISABLE_OFF;
  +    // Enable all priority levels by default.
  +    enable(Priority.ALL);
       this.root.setHierarchy(this);
       rendererMap = new RendererMap();
       defaultFactory = new DefaultCategoryFactory();
  @@ -142,16 +138,18 @@
   
     /**
        Similar to {@link #disable(Priority)} except that the priority
  -     argument is given as a String.  */
  +     argument is given as a String.  
  +
  +     @deprecated Replaced with the {@link #enable(Priority)} familiy
  +     of methods
  +  */
     public
     void disable(String priorityStr) {
  -    if(disable != DISABLE_OVERRIDE) {  
  -      Priority p = Priority.toPriority(priorityStr, null);
  -      if(p != null) {
  -     disable = p.level;
  -      } else {
  -     LogLog.warn("Could not convert ["+priorityStr+"] to Priority.");
  -      }
  +    Priority p = Priority.toPriority(priorityStr, null);
  +    if(p != null) {
  +      disable(p);
  +    } else {
  +      LogLog.warn("Could not convert ["+priorityStr+"] to Priority.");
       }
     }
   
  @@ -162,12 +160,6 @@
        <em>all</em> categories in this hierarchy. Logging requests of
        higher priority then <code>p</code> remain unaffected.
   
  -     <p>Nevertheless, if the {@link
  -     BasicConfigurator#DISABLE_OVERRIDE_KEY} system property is set to
  -     "true" or any value other than "false", then logging requests are
  -     evaluated as usual, i.e. according to the <a
  -     href="../../../../manual.html#selectionRule">Basic Selection Rule</a>.
  -
        <p>The "disable" family of methods are there for speed. They
        allow printing methods such as debug, info, etc. to return
        immediately after an integer comparison without walking the
  @@ -179,12 +171,22 @@
        disable override flag. See {@link PropertyConfigurator} and
        {@link org.apache.log4j.xml.DOMConfigurator}.
   
  +     @deprecated Please use the {@link #enable} familiy of methods instead.
   
        @since 0.8.5 */
     public
     void disable(Priority p) {
  -    if((disable != DISABLE_OVERRIDE) && (p != null)) {
  -      disable = p.level;
  +    if(p != null) {    
  +      switch(p.level) {
  +      case Priority.ALL_INT: enable(Priority.ALL); break;      
  +      case Priority.DEBUG_INT: enable(Priority.INFO); break;      
  +      case Priority.INFO_INT: enable(Priority.WARN); break;
  +      case Priority.WARN_INT: enable(Priority.ERROR); break;      
  +      case Priority.ERROR_INT: enable(Priority.FATAL); break;      
  +      case Priority.FATAL_INT: enable(Priority.OFF); break;      
  +      case Priority.OFF_INT: enable(Priority.OFF); break;      
  +      default: 
  +      }
       }
     }
     
  @@ -236,9 +238,18 @@
        @since 0.8.5 */
     public
     void enableAll() {
  -    disable = DISABLE_OFF;
  +    enable(Priority.ALL);
  +  }
  +
  +  public 
  +  void enable(Priority p) {
  +    if(p != null) {
  +      enableInt = p.level;
  +      enable = p;
  +    }
     }
   
  +
     
     void fireAddAppenderEvent(Category category, Appender appender) {
       if(listeners != null) {
  @@ -270,13 +281,8 @@
        @since 1.2
     */
     public
  -  String getDisableAsString() {
  -    switch(disable) {
  -    case DISABLE_OFF: return "DISABLE_OFF";
  -    case DISABLE_OVERRIDE: return "DISABLE_OVERRIDE";
  -    case Priority.DEBUG_INT: return "DISABLE_DEBUG";
  -    default: return "UNKNOWN_STATE";
  -    }
  +  Priority getEnable() {
  +    return enable;
     }
   
     /**
  @@ -386,33 +392,21 @@
       return root;
     }
   
  +  /**
  +     @deprecated Use {@link isEnabled} instead.
  +   */
  +
     public
  -  boolean isDisabled(int level) {
  -    return disable >=  level;
  +  boolean isDisabled(int level) {    
  +    return enableInt >  level;
     }
   
     /**
  -     Override the shipped code flag if the <code>override</code>
  -     parameter is not null.
  -     
  -     <p>This method is intended to be used by configurators.
  -
  -     <p>If the <code>override</code> paramter is <code>null</code>
  -     then there is nothing to do.  Otherwise, set
  -     <code>Hiearchy.disable</code> to <code>false</code> if override
  -     has a value other than <code>false</code>.  */
  +     @deprecated Deprecated with no replacement.
  +  */
     public
     void overrideAsNeeded(String override) {
  -    // If override is defined, any value other than false will be
  -    // interpreted as true.    
  -    if(override != null) {
  -      LogLog.debug("Handling non-null disable override directive: \""+
  -                override +"\".");
  -      if(OptionConverter.toBoolean(override, true)) {
  -     LogLog.debug("Overriding all disable methods.");
  -     disable = DISABLE_OVERRIDE;
  -      }
  -    }
  +    LogLog.warn("The Hiearchy.overrideAsNeeded method has been deprecated.");
     }
   
     /**
  @@ -434,7 +428,7 @@
   
       getRoot().setPriority(Priority.DEBUG);
       root.setResourceBundle(null);
  -    disable = Hierarchy.DISABLE_OFF;
  +    enableAll();
       
       // the synchronization is needed to prevent JDK 1.2.x hashtable
       // surprises
  @@ -464,16 +458,13 @@
     }
   
     /**
  -     Set the disable override value given a string.
  +     Does mothing.
    
  -     @since 1.1
  +     @deprecated Deprecated with no replacement.
      */
     public
     void setDisableOverride(String override) {
  -    if(OptionConverter.toBoolean(override, true)) {
  -      LogLog.debug("Overriding disable.");
  -      disable =  DISABLE_OVERRIDE;
  -    }
  +    LogLog.warn("The Hiearchy.setDisableOverride method has been deprecated.");    
     }
   
     /**
  
  
  
  1.9       +18 -1     jakarta-log4j/src/java/org/apache/log4j/Priority.java
  
  Index: Priority.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Priority.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Priority.java     2001/07/13 07:53:07     1.8
  +++ Priority.java     2001/07/30 19:30:04     1.9
  @@ -26,16 +26,24 @@
     String levelStr;
     int syslogEquivalent;
   
  +  public final static int OFF_INT = Integer.MAX_VALUE;
     public final static int FATAL_INT = 50000;
     public final static int ERROR_INT = 40000;
     public final static int WARN_INT  = 30000;
     public final static int INFO_INT  = 20000;
     public final static int DEBUG_INT = 10000;
  +  public final static int ALL_INT = Integer.MIN_VALUE;
   
  +
  +  /**
  +     The <code>OFF</code> is used to turn off logging.
  +   */
  +  final static public Priority OFF = new Priority(OFF_INT, "OFF", 0);
  +
  +
     /**
        The <code>FATAL</code> priority designates very severe error
        events that will presumably lead the application to abort.
  -
      */
     final static public Priority FATAL = new Priority(FATAL_INT, "FATAL", 0);
   
  @@ -61,6 +69,11 @@
        application.  */
     final static public Priority DEBUG = new Priority(DEBUG_INT, "DEBUG", 7);
   
  +  /**
  +     The <code>ALL</code> is used to turn on all logging.
  +  */
  +  final static public Priority ALL = new Priority(ALL_INT, "ALL", 7);
  +
     
     /**
        Instantiate a priority object.
  @@ -155,11 +168,13 @@
     static
     Priority toPriority(int val, Priority defaultPriority) {
       switch(val) {
  +    case ALL_INT: return ALL;
       case DEBUG_INT: return DEBUG;
       case INFO_INT: return INFO;
       case WARN_INT: return WARN;
       case ERROR_INT: return ERROR;
       case FATAL_INT: return FATAL;
  +    case OFF_INT: return OFF;
       default: return defaultPriority;
       }
     }
  @@ -177,11 +192,13 @@
       
       String s = sArg.toUpperCase();
   
  +    if(s.equals("ALL")) return Priority.ALL; 
       if(s.equals("DEBUG")) return Priority.DEBUG; 
       if(s.equals("INFO"))  return Priority.INFO;
       if(s.equals("WARN"))  return Priority.WARN;  
       if(s.equals("ERROR")) return Priority.ERROR;
       if(s.equals("FATAL")) return Priority.FATAL;
  +    if(s.equals("OFF")) return Priority.OFF;
       return defaultPriority;
     }
   
  
  
  
  1.30      +8 -8      
jakarta-log4j/src/java/org/apache/log4j/PropertyConfigurator.java
  
  Index: PropertyConfigurator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/PropertyConfigurator.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- PropertyConfigurator.java 2001/07/13 07:53:08     1.29
  +++ PropertyConfigurator.java 2001/07/30 19:30:04     1.30
  @@ -396,15 +396,15 @@
       }
   
       // Check if the config file overides the shipped code flag.
  -    String override = properties.getProperty(
  -                                    BasicConfigurator.DISABLE_OVERRIDE_KEY);
  -    hierarchy.overrideAsNeeded(override);
  +    //String override = properties.getProperty(
  +    //                              BasicConfigurator.DISABLE_OVERRIDE_KEY);
  +    //hierarchy.overrideAsNeeded(override);
   
  -    if(override == null) {
  -      String disableStr = properties.getProperty(BasicConfigurator.DISABLE_KEY);
  -      if(disableStr != null)
  -     hierarchy.disable(disableStr);      
  -    }
  +    //if(override == null) {
  +    String disableStr = properties.getProperty(BasicConfigurator.DISABLE_KEY);
  +    if(disableStr != null)
  +      hierarchy.disable(disableStr);      
  +    //}
       
       
       configureRootCategory(properties, hierarchy);
  
  
  
  1.7       +1 -1      jakarta-log4j/src/java/org/apache/log4j/test/runAll
  
  Index: runAll
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/runAll,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- runAll    2001/06/27 21:37:58     1.6
  +++ runAll    2001/07/30 19:30:05     1.7
  @@ -6,7 +6,7 @@
   ./minreg simple || die "minreg simple FAILED.";
   ./minreg ttcc || die "minreg ttcc FAILED.";
   ./shallow || die "shallow test FAILED."
  -./shippedCodeFlag || die "shippedCodeFlag test FAILED."
  +#./shippedCodeFlag || die "shippedCodeFlag test FAILED."
   ./defaultInit || die "defaultInit test FAILED."
   ./propConfig || die "propConfig test FAILED."
   ./propConfig || die "propConfig test FAILED."
  
  
  

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

Reply via email to