01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10:
11: /*
12: This software is OSI Certified Open Source Software.
13: OSI Certified is a certification mark of the Open Source Initiative.
14:
15: The license (Mozilla version 1.0) can be read at the MMBase site.
16: See http://www.MMBase.org/license
17:
18: */
19:
20: package org.mmbase.util.logging.log4j;
21:
22: import org.apache.log4j.Level;
23: import org.apache.log4j.Priority;
24:
25: /**
26: * LoggerLevel The new Level class for Log4jImpl. It extends
27: * the log4j Level with 2 extra levels, namely `SERVICE' and
28: * `TRACE'.
29: *
30: * @author Michiel Meeuwissen
31: **/
32:
33: public class Log4jLevel extends Level {
34:
35: final static int SERVICE_INT = 15000;
36: final static int TRACE_INT = 5000;
37:
38: // OFF (from log4j.Level)
39: // FATAL
40: // ERROR
41: // WARN
42: // INFO
43: public static final Log4jLevel SERVICE = new Log4jLevel(
44: SERVICE_INT, "SERVICE", 5);
45: // DEBUG
46: public static final Log4jLevel TRACE = new Log4jLevel(TRACE_INT,
47: "TRACE", 7);
48:
49: protected Log4jLevel(int level, String strLevel, int syslogEquiv) {
50: super (level, strLevel, syslogEquiv);
51: }
52:
53: public static Level toLevel(String sArg) {
54: if (sArg == null)
55: return Log4jLevel.TRACE;
56:
57: String stringVal = sArg.toUpperCase();
58:
59: if (stringVal.equals("TRACE"))
60: return Log4jLevel.TRACE;
61: if (stringVal.equals("SERVICE"))
62: return Log4jLevel.SERVICE;
63: return Level.toLevel(sArg);
64: }
65:
66: public static Level toLevel(int i) throws IllegalArgumentException {
67: switch (i) {
68: case TRACE_INT:
69: return Log4jLevel.TRACE;
70: case SERVICE_INT:
71: return Log4jLevel.SERVICE;
72: default:
73: return Level.toLevel(i);
74: }
75: }
76:
77: public static Priority[] getAllPossibleLog4jPriorities() {
78: return new Priority[] { OFF, FATAL, ERROR, WARN, INFO, SERVICE,
79: DEBUG, TRACE };
80: }
81:
82: public static Level toLog4jLevel(String sArg) { // needed?
83: Level result;
84: result = Level.toLevel(sArg, null);
85: if (result != null) {
86: return result;
87: }
88: String s = sArg.toUpperCase();
89: if (s.equals("SERVICE"))
90: return SERVICE;
91: if (s.equals("TRACE"))
92: return TRACE;
93: return DEBUG;
94: }
95:
96: }
|