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 package org.apache.log4j; 18 19 /** 20 * <font color="#AA4444">Refrain from using this class directly, use 21 * the {@link Level} class instead</font>. 22 */ 23 public class Priority { 24 25 /** 26 * The <code>OFF</code> has the highest possible rank and is 27 * intended to turn off logging. 28 */ 29 public static final int OFF_INT = Integer.MAX_VALUE; 30 /** 31 * The <code>FATAL</code> level designates very severe error 32 * events that will presumably lead the application to abort. 33 */ 34 public static final int FATAL_INT = 50000; 35 /** 36 * The <code>ERROR</code> level designates error events that 37 * might still allow the application to continue running. 38 */ 39 public static final int ERROR_INT = 40000; 40 /** 41 * The <code>WARN</code> level designates potentially harmful situations. 42 */ 43 public static final int WARN_INT = 30000; 44 /** 45 * The <code>INFO</code> level designates informational messages 46 * that highlight the progress of the application at coarse-grained 47 * level. 48 */ 49 public static final int INFO_INT = 20000; 50 /** 51 * The <code>DEBUG</code> Level designates fine-grained 52 * informational events that are most useful to debug an 53 * application. 54 */ 55 public static final int DEBUG_INT = 10000; 56 //public final static int FINE_INT = DEBUG_INT; 57 /** 58 * The <code>ALL</code> has the lowest possible rank and is intended to 59 * turn on all logging. 60 */ 61 public static final int ALL_INT = Integer.MIN_VALUE; 62 63 /** 64 * @deprecated Use {@link Level#FATAL} instead. 65 */ 66 public static final Priority FATAL = new Level(FATAL_INT, "FATAL", 0); 67 68 /** 69 * @deprecated Use {@link Level#ERROR} instead. 70 */ 71 public static final Priority ERROR = new Level(ERROR_INT, "ERROR", 3); 72 73 /** 74 * @deprecated Use {@link Level#WARN} instead. 75 */ 76 public static final Priority WARN = new Level(WARN_INT, "WARN", 4); 77 78 /** 79 * @deprecated Use {@link Level#INFO} instead. 80 */ 81 public static final Priority INFO = new Level(INFO_INT, "INFO", 6); 82 83 /** 84 * @deprecated Use {@link Level#DEBUG} instead. 85 */ 86 public static final Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7); 87 88 /* 89 * These variables should be private but were not in Log4j 1.2 so are left the same way here. 90 */ 91 transient int level; 92 transient String levelStr; 93 transient int syslogEquivalent; 94 95 /** 96 * Default constructor for deserialization. 97 */ 98 protected Priority() { 99 level = DEBUG_INT; 100 levelStr = "DEBUG"; 101 syslogEquivalent = 7; 102 } 103 104 /** 105 * Instantiate a level object. 106 * @param level The level value. 107 * @param levelStr The level name. 108 * @param syslogEquivalent The equivalent syslog value. 109 */ 110 protected Priority(int level, String levelStr, int syslogEquivalent) { 111 this.level = level; 112 this.levelStr = levelStr; 113 this.syslogEquivalent = syslogEquivalent; 114 } 115 116 /** 117 * Two priorities are equal if their level fields are equal. 118 * @param o The Object to check. 119 * @return true if the objects are equal, false otherwise. 120 * 121 * @since 1.2 122 */ 123 public boolean equals(Object o) { 124 if (o instanceof Priority) { 125 Priority r = (Priority) o; 126 return (this.level == r.level); 127 } else { 128 return false; 129 } 130 } 131 132 /** 133 * Return the syslog equivalent of this priority as an integer. 134 * @return The equivalent syslog value. 135 */ 136 public 137 final int getSyslogEquivalent() { 138 return syslogEquivalent; 139 } 140 141 142 /** 143 * Returns <code>true</code> if this level has a higher or equal 144 * level than the level passed as argument, <code>false</code> 145 * otherwise. 146 * <p/> 147 * <p>You should think twice before overriding the default 148 * implementation of <code>isGreaterOrEqual</code> method. 149 * @param r The Priority to check. 150 * @return true if the current level is greater or equal to the specified Priority. 151 */ 152 public boolean isGreaterOrEqual(Priority r) { 153 return level >= r.level; 154 } 155 156 /** 157 * Return all possible priorities as an array of Level objects in 158 * descending order. 159 * @return An array of all possible Priorities. 160 * 161 * @deprecated This method will be removed with no replacement. 162 */ 163 public static Priority[] getAllPossiblePriorities() { 164 return new Priority[]{Priority.FATAL, Priority.ERROR, Level.WARN, 165 Priority.INFO, Priority.DEBUG}; 166 } 167 168 169 /** 170 * Returns the string representation of this priority. 171 * @return The name of the Priority. 172 */ 173 public final String toString() { 174 return levelStr; 175 } 176 177 /** 178 * Returns the integer representation of this level. 179 * @return The integer value of this level. 180 */ 181 public final int toInt() { 182 return level; 183 } 184 185 /** 186 * @param sArg The name of the Priority. 187 * @return The Priority matching the name. 188 * @deprecated Please use the {@link Level#toLevel(String)} method instead. 189 */ 190 public static Priority toPriority(String sArg) { 191 return Level.toLevel(sArg); 192 } 193 194 /** 195 * @param val The value of the Priority. 196 * @return The Priority matching the value. 197 * @deprecated Please use the {@link Level#toLevel(int)} method instead. 198 */ 199 public static Priority toPriority(int val) { 200 return toPriority(val, Priority.DEBUG); 201 } 202 203 /** 204 * @param val The value of the Priority. 205 * @param defaultPriority The default Priority to use if the value is invalid. 206 * @return The Priority matching the value or the default Priority if no match is found. 207 * @deprecated Please use the {@link Level#toLevel(int, Level)} method instead. 208 */ 209 public static Priority toPriority(int val, Priority defaultPriority) { 210 return Level.toLevel(val, (Level) defaultPriority); 211 } 212 213 /** 214 * @param sArg The name of the Priority. 215 * @param defaultPriority The default Priority to use if the name is not found. 216 * @return The Priority matching the name or the default Priority if no match is found. 217 * @deprecated Please use the {@link Level#toLevel(String, Level)} method instead. 218 */ 219 public static Priority toPriority(String sArg, Priority defaultPriority) { 220 return Level.toLevel(sArg, (Level) defaultPriority); 221 } 222 }