Priority xref

View Javadoc

    1   /*
    2    * Copyright 2001-2004 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  // Contributors:  Kitching Simon <Simon.Kitching@orange.ch>
    18
    19  package org.apache.log4j;
    20
    21  // Contributors:  Kitching Simon <Simon.Kitching@OOOrange.ch>
    22
    23  /**
    24     <font color="#AA4444">Refrain from using this class directly, use
    25     the {@link Level} class instead</font>.
    26
    27     @author Ceki G&uuml;lc&uuml; */
    28  public class Priority {
    29
    30    transient int level;
    31    transient String levelStr;
    32    transient int syslogEquivalent;
    33
    34    public final static int OFF_INT = Integer.MAX_VALUE;
    35    public final static int FATAL_INT = 50000;
    36    public final static int ERROR_INT = 40000;
    37    public final static int WARN_INT  = 30000;
    38    public final static int INFO_INT  = 20000;
    39    public final static int DEBUG_INT = 10000;
    40      //public final static int FINE_INT = DEBUG_INT;
    41    public final static int ALL_INT = Integer.MIN_VALUE;
    42
    43    /**
    44     * @deprecated Use {@link Level#FATAL} instead.
    45     */
    46    final static public Priority FATAL = new Level(FATAL_INT, "FATAL", 0);
    47
    48    /**
    49     * @deprecated Use {@link Level#ERROR} instead.
    50     */
    51    final static public Priority ERROR = new Level(ERROR_INT, "ERROR", 3);
    52
    53    /**
    54     * @deprecated Use {@link Level#WARN} instead.
    55     */
    56    final static public Priority WARN  = new Level(WARN_INT, "WARN",  4);
    57
    58    /**
    59     * @deprecated Use {@link Level#INFO} instead.
    60     */
    61    final static public Priority INFO  = new Level(INFO_INT, "INFO",  6);
    62
    63    /**
    64     * @deprecated Use {@link Level#DEBUG} instead.
    65     */
    66    final static public Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
    67
    68
    69    /**
    70      * Default constructor for deserialization.
    71      */
    72    protected Priority() {
    73        level = DEBUG_INT;
    74        levelStr = "DEBUG";
    75        syslogEquivalent = 7;
    76    }
    77
    78    /**
    79       Instantiate a level object.
    80     */
    81    protected
    82    Priority(int level, String levelStr, int syslogEquivalent) {
    83      this.level = level;
    84      this.levelStr = levelStr;
    85      this.syslogEquivalent = syslogEquivalent;
    86    }
    87
    88    /**
    89       Two priorities are equal if their level fields are equal.
    90       @since 1.2
    91     */
    92    public
    93    boolean equals(Object o) {
    94      if(o instanceof Priority) {
    95        Priority r = (Priority) o;
    96        return (this.level == r.level);
    97      } else {
    98        return false;
    99      }
    100   }
    101
    102   /**
    103      Return the syslog equivalent of this priority as an integer.
    104    */
    105   public
    106   final
    107   int getSyslogEquivalent() {
    108     return syslogEquivalent;
    109   }
    110
    111
    112
    113   /**
    114      Returns <code>true</code> if this level has a higher or equal
    115      level than the level passed as argument, <code>false</code>
    116      otherwise.
    117
    118      <p>You should think twice before overriding the default
    119      implementation of <code>isGreaterOrEqual</code> method.
    120
    121   */
    122   public
    123   boolean isGreaterOrEqual(Priority r) {
    124     return level >= r.level;
    125   }
    126
    127   /**
    128      Return all possible priorities as an array of Level objects in
    129      descending order.
    130
    131      @deprecated This method will be removed with no replacement.
    132   */
    133   public
    134   static
    135   Priority[] getAllPossiblePriorities() {
    136     return new Priority[] {Priority.FATAL, Priority.ERROR, Level.WARN,
    137                                                    Priority.INFO, Priority.DEBUG};
    138   }
    139
    140
    141   /**
    142      Returns the string representation of this priority.
    143    */
    144   final
    145   public
    146   String toString() {
    147     return levelStr;
    148   }
    149
    150   /**
    151      Returns the integer representation of this level.
    152    */
    153   public
    154   final
    155   int toInt() {
    156     return level;
    157   }
    158
    159   /**
    160    * @deprecated Please use the {@link Level#toLevel(String)} method instead.
    161   */
    162   public
    163   static
    164   Priority toPriority(String sArg) {
    165     return Level.toLevel(sArg);
    166   }
    167
    168   /**
    169    * @deprecated Please use the {@link Level#toLevel(int)} method instead.
    170    */
    171   public
    172   static
    173   Priority toPriority(int val) {
    174     return toPriority(val, Priority.DEBUG);
    175   }
    176
    177   /**
    178    * @deprecated Please use the {@link Level#toLevel(int, Level)} method instead.
    179   */
    180   public
    181   static
    182   Priority toPriority(int val, Priority defaultPriority) {
    183     return Level.toLevel(val, (Level) defaultPriority);
    184   }
    185
    186   /**
    187    * @deprecated Please use the {@link Level#toLevel(String, Level)} method instead.
    188    */
    189   public
    190   static
    191   Priority toPriority(String sArg, Priority defaultPriority) {
    192     return Level.toLevel(sArg, (Level) defaultPriority);
    193   }
    194 }