1 package jalview.javascript.log4j;
3 import java.util.Locale;
5 import java.io.IOException;
6 import java.io.ObjectInputStream;
7 import java.io.ObjectOutputStream;
8 import java.io.ObjectStreamException;
9 import java.io.Serializable;
12 * Defines the minimum set of levels recognized by the system, that is
13 * <code>OFF</code>, <code>FATAL</code>, <code>ERROR</code>, <code>WARN</code>,
14 * <code>INFO</code>, <code>DEBUG</code> and <code>ALL</code>.
17 * The <code>Level</code> class may be subclassed to define a larger level set.
20 * @author Ceki Gülcü
22 public class Level extends Priority implements Serializable
25 private static final String ALL_NAME = "ALL";
27 private static final String TRACE_NAME = "TRACE";
29 private static final String DEBUG_NAME = "DEBUG";
31 private static final String INFO_NAME = "INFO";
33 private static final String WARN_NAME = "WARN";
35 private static final String ERROR_NAME = "ERROR";
37 private static final String FATAL_NAME = "FATAL";
39 private static final String OFF_NAME = "OFF";
42 * TRACE level integer value.
46 public static final int TRACE_INT = 5000;
49 * The <code>OFF</code> has the highest possible rank and is intended to turn
52 final static public Level OFF = new Level(OFF_INT, OFF_NAME, 0);
55 * The <code>FATAL</code> level designates very severe error events that will
56 * presumably lead the application to abort.
58 final static public Level FATAL = new Level(FATAL_INT, FATAL_NAME, 0);
61 * The <code>ERROR</code> level designates error events that might still allow
62 * the application to continue running.
64 final static public Level ERROR = new Level(ERROR_INT, ERROR_NAME, 3);
67 * The <code>WARN</code> level designates potentially harmful situations.
69 final static public Level WARN = new Level(WARN_INT, WARN_NAME, 4);
72 * The <code>INFO</code> level designates informational messages that
73 * highlight the progress of the application at coarse-grained level.
75 final static public Level INFO = new Level(INFO_INT, INFO_NAME, 6);
78 * The <code>DEBUG</code> Level designates fine-grained informational events
79 * that are most useful to debug an application.
81 final static public Level DEBUG = new Level(DEBUG_INT, DEBUG_NAME, 7);
84 * The <code>TRACE</code> Level designates finer-grained informational events
85 * than the <code>DEBUG</code level.
89 public static final Level TRACE = new Level(TRACE_INT, TRACE_NAME, 7);
92 * The <code>ALL</code> has the lowest possible rank and is intended to turn
95 final static public Level ALL = new Level(ALL_INT, ALL_NAME, 7);
98 * Serialization version id.
100 static final long serialVersionUID = 3491141966387921974L;
103 * Instantiate a Level object.
105 protected Level(int level, String levelStr, int syslogEquivalent)
107 super(level, levelStr, syslogEquivalent);
111 * Convert the string passed as argument to a level. If the conversion fails,
112 * then this method returns {@link #DEBUG}.
114 public static Level toLevel(String sArg)
116 return toLevel(sArg, Level.DEBUG);
120 * Convert an integer passed as argument to a level. If the conversion fails,
121 * then this method returns {@link #DEBUG}.
123 public static Level toLevel(int val)
125 return toLevel(val, Level.DEBUG);
129 * Convert an integer passed as argument to a level. If the conversion fails,
130 * then this method returns the specified default.
132 public static Level toLevel(int val, Level defaultLevel)
158 * Convert the string passed as argument to a level. If the conversion fails,
159 * then this method returns the value of <code>defaultLevel</code>.
161 public static Level toLevel(String sArg, Level defaultLevel)
167 String s = sArg.toUpperCase(Locale.ROOT);
169 if (s.equals(ALL_NAME))
173 if (s.equals(DEBUG_NAME))
177 if (s.equals(INFO_NAME))
181 if (s.equals(WARN_NAME))
185 if (s.equals(ERROR_NAME))
189 if (s.equals(FATAL_NAME))
193 if (s.equals(OFF_NAME))
197 if (s.equals(TRACE_NAME))
202 // For Turkish i problem, see bug 40937
204 if (s.equals("\u0130NFO"))
212 * Custom deserialization of Level.
215 * serialization stream.
216 * @throws IOException
218 * @throws ClassNotFoundException
219 * if class not found.
221 private void readObject(final ObjectInputStream s)
222 throws IOException, ClassNotFoundException
224 s.defaultReadObject();
226 syslogEquivalent = s.readInt();
227 levelStr = s.readUTF();
228 if (levelStr == null)
238 * serialization stream.
239 * @throws IOException
240 * if exception during serialization.
242 private void writeObject(final ObjectOutputStream s) throws IOException
244 s.defaultWriteObject();
246 s.writeInt(syslogEquivalent);
247 s.writeUTF(levelStr);
251 * Resolved deserialized level to one of the stock instances. May be overriden
252 * in classes derived from Level.
254 * @return resolved object.
255 * @throws ObjectStreamException
256 * if exception during resolution.
258 private Object readResolve() throws ObjectStreamException
261 // if the deserizalized object is exactly an instance of Level
263 if (getClass() == Level.class)
265 return toLevel(level);
268 // extension of Level can't substitute stock item