01: /*
02: This software is OSI Certified Open Source Software.
03: OSI Certified is a certification mark of the Open Source Initiative.
04:
05: The license (Mozilla version 1.0) can be read at the MMBase site.
06: See http://www.MMBase.org/license
07:
08: */
09:
10: package org.mmbase.util.logging;
11:
12: /**
13: * This class is a kind of `enum' type, for logging priorities. It has
14: * static instances and only a private constructor. And a function to
15: * translate to an int, which is handy for use in a switch.
16: *
17: * @author Michiel Meeuwissen
18: **/
19:
20: public final class Level implements java.io.Serializable {
21:
22: /**
23: * A possible result of {@link #toInt}
24: */
25:
26: public final static int TRACE_INT = 5000, DEBUG_INT = 10000,
27: SERVICE_INT = 15000, INFO_INT = 20000, WARN_INT = 30000,
28: ERROR_INT = 40000, FATAL_INT = 50000,
29: OFF_INT = Integer.MAX_VALUE;
30:
31: /**
32: * A constant. Main use is for the method {@link Logger#setLevel}
33: */
34: public final static Level TRACE = new Level(TRACE_INT, "TRACE"),
35: DEBUG = new Level(DEBUG_INT, "DEBUG"), SERVICE = new Level(
36: SERVICE_INT, "SERVICE"), INFO = new Level(INFO_INT,
37: "INFO"), WARN = new Level(WARN_INT, "WARN"),
38: ERROR = new Level(ERROR_INT, "ERROR"), FATAL = new Level(
39: FATAL_INT, "FATAL"),
40: OFF = new Level(OFF_INT, "OFF");
41:
42: private int level;
43: private String string;
44:
45: private Level(int p, String s) {
46: level = p;
47: string = s;
48: }
49:
50: public static Level toLevel(String level) {
51:
52: String s = level.toUpperCase();
53: if (s.equals("TRACE"))
54: return TRACE;
55: if (s.equals("DEBUG"))
56: return DEBUG;
57: if (s.equals("SERVICE"))
58: return SERVICE;
59: if (s.equals("INFO"))
60: return INFO;
61: if (s.equals("WARN"))
62: return WARN;
63: if (s.equals("ERROR"))
64: return ERROR;
65: if (s.equals("FATAL"))
66: return FATAL;
67: if (s.equals("OFF"))
68: return OFF;
69:
70: return DEBUG;
71:
72: }
73:
74: /**
75: * Makes an integer from this object.
76: */
77: public final int toInt() {
78: return level;
79: }
80:
81: public final String toString() {
82: return string;
83: }
84:
85: }
|