001: /*
002: * Copyright 1999-2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: // Contributors: Kitching Simon <Simon.Kitching@orange.ch>
018: package org.apache.log4j;
019:
020: /**
021: <font color="#AA4444">Refrain from using this class directly, use
022: the {@link Level} class instead</font>.
023:
024: @author Ceki Gülcü */
025: public class Priority {
026:
027: transient int level;
028: transient String levelStr;
029: transient int syslogEquivalent;
030:
031: public final static int OFF_INT = Integer.MAX_VALUE;
032: public final static int FATAL_INT = 50000;
033: public final static int ERROR_INT = 40000;
034: public final static int WARN_INT = 30000;
035: public final static int INFO_INT = 20000;
036: public final static int DEBUG_INT = 10000;
037: //public final static int FINE_INT = DEBUG_INT;
038: public final static int ALL_INT = Integer.MIN_VALUE;
039:
040: /**
041: * @deprecated Use {@link Level#FATAL} instead.
042: */
043: final static public Priority FATAL = new Level(FATAL_INT, "FATAL",
044: 0);
045:
046: /**
047: * @deprecated Use {@link Level#ERROR} instead.
048: */
049: final static public Priority ERROR = new Level(ERROR_INT, "ERROR",
050: 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",
066: 7);
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 Priority(int level, String levelStr, int syslogEquivalent) {
081: this .level = level;
082: this .levelStr = levelStr;
083: this .syslogEquivalent = syslogEquivalent;
084: }
085:
086: /**
087: Two priorities are equal if their level fields are equal.
088: @since 1.2
089: */
090: public boolean equals(Object o) {
091: if (o instanceof Priority) {
092: Priority r = (Priority) o;
093: return (this .level == r.level);
094: } else {
095: return false;
096: }
097: }
098:
099: /**
100: Return the syslog equivalent of this priority as an integer.
101: */
102: public final int getSyslogEquivalent() {
103: return syslogEquivalent;
104: }
105:
106: /**
107: Returns <code>true</code> if this level has a higher or equal
108: level than the level passed as argument, <code>false</code>
109: otherwise.
110:
111: <p>You should think twice before overriding the default
112: implementation of <code>isGreaterOrEqual</code> method.
113:
114: */
115: public boolean isGreaterOrEqual(Priority r) {
116: return level >= r.level;
117: }
118:
119: /**
120: Return all possible priorities as an array of Level objects in
121: descending order.
122:
123: @deprecated This method will be removed with no replacement.
124: */
125: public static Priority[] getAllPossiblePriorities() {
126: return new Priority[] { Priority.FATAL, Priority.ERROR,
127: Level.WARN, Priority.INFO, Priority.DEBUG };
128: }
129:
130: /**
131: Returns the string representation of this priority.
132: */
133: final public String toString() {
134: return levelStr;
135: }
136:
137: /**
138: Returns the integer representation of this level.
139: */
140: public final int toInt() {
141: return level;
142: }
143:
144: /**
145: * @deprecated Please use the {@link Level#toLevel(String)} method instead.
146: */
147: public static Priority toPriority(String sArg) {
148: return Level.toLevel(sArg);
149: }
150:
151: /**
152: * @deprecated Please use the {@link Level#toLevel(int)} method instead.
153: */
154: public static Priority toPriority(int val) {
155: return toPriority(val, Priority.DEBUG);
156: }
157:
158: /**
159: * @deprecated Please use the {@link Level#toLevel(int, Level)} method instead.
160: */
161: public static Priority toPriority(int val, Priority defaultPriority) {
162: return Level.toLevel(val, (Level) defaultPriority);
163: }
164:
165: /**
166: * @deprecated Please use the {@link Level#toLevel(String, Level)} method instead.
167: */
168: public static Priority toPriority(String sArg,
169: Priority defaultPriority) {
170: return Level.toLevel(sArg, (Level) defaultPriority);
171: }
172: }
|