KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > Priority


1 /*
2  * Copyright 1999-2005 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 /**
22    <font color="#AA4444">Refrain from using this class directly, use
23    the {@link Level} class instead</font>.
24
25    @author Ceki G&uuml;lc&uuml; */

26 public class Priority {
27
28   transient int level;
29   transient String JavaDoc levelStr;
30   transient int syslogEquivalent;
31
32   public final static int OFF_INT = Integer.MAX_VALUE;
33   public final static int FATAL_INT = 50000;
34   public final static int ERROR_INT = 40000;
35   public final static int WARN_INT = 30000;
36   public final static int INFO_INT = 20000;
37   public final static int DEBUG_INT = 10000;
38     //public final static int FINE_INT = DEBUG_INT;
39
public final static int ALL_INT = Integer.MIN_VALUE;
40
41   /**
42    * @deprecated Use {@link Level#FATAL} instead.
43    */

44   final static public Priority FATAL = new Level(FATAL_INT, "FATAL", 0);
45
46   /**
47    * @deprecated Use {@link Level#ERROR} instead.
48    */

49   final static public Priority ERROR = new Level(ERROR_INT, "ERROR", 3);
50
51   /**
52    * @deprecated Use {@link Level#WARN} instead.
53    */

54   final static public Priority WARN = new Level(WARN_INT, "WARN", 4);
55
56   /**
57    * @deprecated Use {@link Level#INFO} instead.
58    */

59   final static public Priority INFO = new Level(INFO_INT, "INFO", 6);
60
61   /**
62    * @deprecated Use {@link Level#DEBUG} instead.
63    */

64   final static public Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
65
66
67   /**
68     * Default constructor for deserialization.
69     */

70   protected Priority() {
71       level = DEBUG_INT;
72       levelStr = "DEBUG";
73       syslogEquivalent = 7;
74   }
75
76   /**
77      Instantiate a level object.
78    */

79   protected
80   Priority(int level, String JavaDoc levelStr, int syslogEquivalent) {
81     this.level = level;
82     this.levelStr = levelStr;
83     this.syslogEquivalent = syslogEquivalent;
84   }
85
86   /**
87      Two priorities are equal if their level fields are equal.
88      @since 1.2
89    */

90   public
91   boolean equals(Object JavaDoc o) {
92     if(o instanceof Priority) {
93       Priority r = (Priority) o;
94       return (this.level == r.level);
95     } else {
96       return false;
97     }
98   }
99
100   /**
101      Return the syslog equivalent of this priority as an integer.
102    */

103   public
104   final
105   int getSyslogEquivalent() {
106     return syslogEquivalent;
107   }
108
109
110    
111   /**
112      Returns <code>true</code> if this level has a higher or equal
113      level than the level passed as argument, <code>false</code>
114      otherwise.
115      
116      <p>You should think twice before overriding the default
117      implementation of <code>isGreaterOrEqual</code> method.
118
119   */

120   public
121   boolean isGreaterOrEqual(Priority r) {
122     return level >= r.level;
123   }
124
125   /**
126      Return all possible priorities as an array of Level objects in
127      descending order.
128
129      @deprecated This method will be removed with no replacement.
130   */

131   public
132   static
133   Priority[] getAllPossiblePriorities() {
134     return new Priority[] {Priority.FATAL, Priority.ERROR, Level.WARN,
135                                                    Priority.INFO, Priority.DEBUG};
136   }
137
138
139   /**
140      Returns the string representation of this priority.
141    */

142   final
143   public
144   String JavaDoc toString() {
145     return levelStr;
146   }
147
148   /**
149      Returns the integer representation of this level.
150    */

151   public
152   final
153   int toInt() {
154     return level;
155   }
156
157   /**
158    * @deprecated Please use the {@link Level#toLevel(String)} method instead.
159   */

160   public
161   static
162   Priority toPriority(String JavaDoc sArg) {
163     return Level.toLevel(sArg);
164   }
165
166   /**
167    * @deprecated Please use the {@link Level#toLevel(int)} method instead.
168    */

169   public
170   static
171   Priority toPriority(int val) {
172     return toPriority(val, Priority.DEBUG);
173   }
174
175   /**
176    * @deprecated Please use the {@link Level#toLevel(int, Level)} method instead.
177   */

178   public
179   static
180   Priority toPriority(int val, Priority defaultPriority) {
181     return Level.toLevel(val, (Level) defaultPriority);
182   }
183
184   /**
185    * @deprecated Please use the {@link Level#toLevel(String, Level)} method instead.
186    */

187   public
188   static
189   Priority toPriority(String JavaDoc sArg, Priority defaultPriority) {
190     return Level.toLevel(sArg, (Level) defaultPriority);
191   }
192 }
Popular Tags