001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 * 
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 * 
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018// Contributors:  Kitching Simon <Simon.Kitching@orange.ch>
019
020package org.apache.log4j;
021
022/**
023   <font color="#AA4444">Refrain from using this class directly, use
024   the {@link Level} class instead</font>.
025
026   @author Ceki G&uuml;lc&uuml; */
027public class Priority {
028
029  transient int level;
030  transient String levelStr;
031  transient int syslogEquivalent;
032
033  public final static int OFF_INT = Integer.MAX_VALUE;
034  public final static int FATAL_INT = 50000;
035  public final static int ERROR_INT = 40000;
036  public final static int WARN_INT  = 30000;
037  public final static int INFO_INT  = 20000;
038  public final static int DEBUG_INT = 10000;
039    //public final static int FINE_INT = DEBUG_INT;
040  public final static int ALL_INT = Integer.MIN_VALUE;
041
042  /**
043   * @deprecated Use {@link Level#FATAL} instead.
044   */
045  final static public Priority FATAL = new Level(FATAL_INT, "FATAL", 0);
046
047  /**
048   * @deprecated Use {@link Level#ERROR} instead.
049   */
050  final static public Priority ERROR = new Level(ERROR_INT, "ERROR", 3);
051
052  /**
053   * @deprecated Use {@link Level#WARN} instead.
054   */
055  final static public Priority WARN  = new Level(WARN_INT, "WARN",  4);
056
057  /**
058   * @deprecated Use {@link Level#INFO} instead.
059   */
060  final static public Priority INFO  = new Level(INFO_INT, "INFO",  6);
061
062  /**
063   * @deprecated Use {@link Level#DEBUG} instead.
064   */
065  final static public Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
066
067
068  /**
069    * Default constructor for deserialization.
070    */
071  protected Priority() {
072      level = DEBUG_INT;
073      levelStr = "DEBUG";
074      syslogEquivalent = 7;
075  }
076
077  /**
078     Instantiate a level object.
079   */
080  protected
081  Priority(int level, String levelStr, int syslogEquivalent) {
082    this.level = level;
083    this.levelStr = levelStr;
084    this.syslogEquivalent = syslogEquivalent;
085  }
086
087  /**
088     Two priorities are equal if their level fields are equal.
089     @since 1.2
090   */
091  public
092  boolean equals(Object o) {
093    if(o instanceof Priority) {
094      Priority r = (Priority) o;
095      return (this.level == r.level);
096    } else {
097      return false;
098    }
099  }
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}