1 package jalview.javascript.log4j;
3 import java.io.IOException;
4 import java.io.ObjectInputStream;
5 import java.io.ObjectOutputStream;
6 import java.io.ObjectStreamException;
7 import java.io.Serializable;
10 * Defines the minimum set of levels recognized by the system, that is
11 * <code>OFF</code>, <code>FATAL</code>, <code>ERROR</code>, <code>WARN</code>,
12 * <code>INFO</code>, <code>DEBUG</code> and <code>ALL</code>.
15 * The <code>Level</code> class may be subclassed to define a larger level set.
18 * @author Ceki Gülcü
20 public class Level extends Priority implements Serializable
23 private static final String ALL_NAME = "ALL";
25 private static final String TRACE_NAME = "TRACE";
27 private static final String DEBUG_NAME = "DEBUG";
29 private static final String INFO_NAME = "INFO";
31 private static final String WARN_NAME = "WARN";
33 private static final String ERROR_NAME = "ERROR";
35 private static final String FATAL_NAME = "FATAL";
37 private static final String OFF_NAME = "OFF";
40 * TRACE level integer value.
44 public static final int TRACE_INT = 5000;
47 * The <code>OFF</code> has the highest possible rank and is intended to turn
50 final static public Level OFF = new Level(OFF_INT, OFF_NAME, 0);
53 * The <code>FATAL</code> level designates very severe error events that will
54 * presumably lead the application to abort.
56 final static public Level FATAL = new Level(FATAL_INT, FATAL_NAME, 0);
59 * The <code>ERROR</code> level designates error events that might still allow
60 * the application to continue running.
62 final static public Level ERROR = new Level(ERROR_INT, ERROR_NAME, 3);
65 * The <code>WARN</code> level designates potentially harmful situations.
67 final static public Level WARN = new Level(WARN_INT, WARN_NAME, 4);
70 * The <code>INFO</code> level designates informational messages that
71 * highlight the progress of the application at coarse-grained level.
73 final static public Level INFO = new Level(INFO_INT, INFO_NAME, 6);
76 * The <code>DEBUG</code> Level designates fine-grained informational events
77 * that are most useful to debug an application.
79 final static public Level DEBUG = new Level(DEBUG_INT, DEBUG_NAME, 7);
82 * The <code>TRACE</code> Level designates finer-grained informational events
83 * than the <code>DEBUG</code level.
87 public static final Level TRACE = new Level(TRACE_INT, TRACE_NAME, 7);
90 * The <code>ALL</code> has the lowest possible rank and is intended to turn
93 final static public Level ALL = new Level(ALL_INT, ALL_NAME, 7);
96 * Serialization version id.
98 static final long serialVersionUID = 3491141966387921974L;
101 * Instantiate a Level object.
103 protected Level(int level, String levelStr, int syslogEquivalent)
105 super(level, levelStr, syslogEquivalent);
109 * Convert the string passed as argument to a level. If the conversion fails,
110 * then this method returns {@link #DEBUG}.
112 public static Level toLevel(String sArg)
114 return toLevel(sArg, Level.DEBUG);
118 * Convert an integer passed as argument to a level. If the conversion fails,
119 * then this method returns {@link #DEBUG}.
121 public static Level toLevel(int val)
123 return toLevel(val, Level.DEBUG);
127 * Convert an integer passed as argument to a level. If the conversion fails,
128 * then this method returns the specified default.
130 public static Level toLevel(int val, Level defaultLevel)
156 * Convert the string passed as argument to a level. If the conversion fails,
157 * then this method returns the value of <code>defaultLevel</code>.
159 public static Level toLevel(String sArg, Level defaultLevel)
165 String s = sArg.toUpperCase();
167 if (s.equals(ALL_NAME))
171 if (s.equals(DEBUG_NAME))
175 if (s.equals(INFO_NAME))
179 if (s.equals(WARN_NAME))
183 if (s.equals(ERROR_NAME))
187 if (s.equals(FATAL_NAME))
191 if (s.equals(OFF_NAME))
195 if (s.equals(TRACE_NAME))
200 // For Turkish i problem, see bug 40937
202 if (s.equals("\u0130NFO"))
210 * Custom deserialization of Level.
213 * serialization stream.
214 * @throws IOException
216 * @throws ClassNotFoundException
217 * if class not found.
219 private void readObject(final ObjectInputStream s)
220 throws IOException, ClassNotFoundException
222 s.defaultReadObject();
224 syslogEquivalent = s.readInt();
225 levelStr = s.readUTF();
226 if (levelStr == null)
236 * serialization stream.
237 * @throws IOException
238 * if exception during serialization.
240 private void writeObject(final ObjectOutputStream s) throws IOException
242 s.defaultWriteObject();
244 s.writeInt(syslogEquivalent);
245 s.writeUTF(levelStr);
249 * Resolved deserialized level to one of the stock instances. May be overriden
250 * in classes derived from Level.
252 * @return resolved object.
253 * @throws ObjectStreamException
254 * if exception during resolution.
256 private Object readResolve() throws ObjectStreamException
259 // if the deserizalized object is exactly an instance of Level
261 if (getClass() == Level.class)
263 return toLevel(level);
266 // extension of Level can't substitute stock item