• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    <b>Refrain from using this class directly, use
25    the {@link Level} class instead</b>.
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     @Deprecated
52     final static public Priority ERROR = new Level(ERROR_INT, "ERROR", 3);
53 
54     /**
55      * @deprecated Use {@link Level#WARN} instead.
56      */
57     @Deprecated
58     final static public Priority WARN = new Level(WARN_INT, "WARN", 4);
59 
60     /**
61      * @deprecated Use {@link Level#INFO} instead.
62      */
63     @Deprecated
64     final static public Priority INFO = new Level(INFO_INT, "INFO", 6);
65 
66     /**
67      * @deprecated Use {@link Level#DEBUG} instead.
68      */
69     @Deprecated
70     final static public Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
71 
72     /**
73       * Default constructor for deserialization.
74       */
Priority()75     protected Priority() {
76         level = DEBUG_INT;
77         levelStr = "DEBUG";
78         syslogEquivalent = 7;
79     }
80 
81     /**
82        Instantiate a level object.
83        @param
84      */
85 
86     /**
87      * Instantiate a level object.
88      *
89      * @param level a level as in int
90      * @param levelStr  a levelStr
91      * @param syslogEquivalent the syslog equivalent level integer
92      */
Priority(int level, String levelStr, int syslogEquivalent)93     protected Priority(int level, String levelStr, int syslogEquivalent) {
94         this.level = level;
95         this.levelStr = levelStr;
96         this.syslogEquivalent = syslogEquivalent;
97     }
98 
99     /**
100        Two priorities are equal if their level fields are equal.
101        @since 1.2
102      */
equals(Object o)103     public boolean equals(Object o) {
104         if (o instanceof Priority) {
105             Priority r = (Priority) o;
106             return (this.level == r.level);
107         } else {
108             return false;
109         }
110     }
111 
112     /**
113        Return the syslog equivalent of this priority as an integer.
114        @return the Syslog Equivalent of this Priority
115      */
getSyslogEquivalent()116     public final int getSyslogEquivalent() {
117         return syslogEquivalent;
118     }
119 
120     /**
121      * Returns <code>true</code> if this level has a higher or equal
122      *  level than the level passed as argument, <code>false</code>
123      *  otherwise.
124      *
125      *  <p>You should think twice before overriding the default
126      *  implementation of <code>isGreaterOrEqual</code> method.
127      *
128      * @param r a priority
129      * @return a boolean
130      */
isGreaterOrEqual(Priority r)131     public boolean isGreaterOrEqual(Priority r) {
132         return level >= r.level;
133     }
134 
135     /**
136        Return all possible priorities as an array of Level objects in
137        descending order.
138 
139        @deprecated This method will be removed with no replacement.
140        @return array of all possible priorities
141     */
142     @Deprecated
getAllPossiblePriorities()143     public static Priority[] getAllPossiblePriorities() {
144         return new Priority[] { Priority.FATAL, Priority.ERROR, Level.WARN, Priority.INFO, Priority.DEBUG };
145     }
146 
147     /**
148        Returns the string representation of this priority.
149      */
toString()150     final public String toString() {
151         return levelStr;
152     }
153 
154     /**
155      * Returns the integer representation of this level.
156      *
157      * @return integer representation of this level
158      */
toInt()159     public final int toInt() {
160         return level;
161     }
162 
163     /**
164      * @deprecated Please use the {@link Level#toLevel(String)} method instead.
165      *
166      * @param sArg a string to convert to a Priority
167      * @return the corresponding Priority
168     */
169     @Deprecated
toPriority(String sArg)170     public static Priority toPriority(String sArg) {
171         return Level.toLevel(sArg);
172     }
173 
174     /**
175      * @deprecated Please use the {@link Level#toLevel(int)} method instead.
176      *
177      * @param val an integer to convert to a Priority
178      * @return the corresponding Priority
179      */
180     @Deprecated
toPriority(int val)181     public static Priority toPriority(int val) {
182         return toPriority(val, Priority.DEBUG);
183     }
184 
185     /**
186      * @deprecated Please use the {@link Level#toLevel(int, Level)} method instead.
187      *
188      * @param val an integer value
189      * @param defaultPriority a default priority value
190      * @return corresponding Priority value
191      */
192     @Deprecated
toPriority(int val, Priority defaultPriority)193     public static Priority toPriority(int val, Priority defaultPriority) {
194         return Level.toLevel(val, (Level) defaultPriority);
195     }
196 
197     /**
198      * @deprecated Please use the {@link Level#toLevel(String, Level)} method instead.
199      * @param sArg string value
200      * @param defaultPriority a default Priority
201      * @return a Priority
202      */
203     @Deprecated
toPriority(String sArg, Priority defaultPriority)204     public static Priority toPriority(String sArg, Priority defaultPriority) {
205         return Level.toLevel(sArg, (Level) defaultPriority);
206     }
207 }
208