Priority xref

View Javadoc

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