KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > logging > log4j > Log4jLevel


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

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 import org.apache.log4j.Level;
22 import org.apache.log4j.Priority;
23
24 /**
25  * LoggerLevel The new Level class for Log4jImpl. It extends
26  * the log4j Level with 2 extra levels, namely `SERVICE' and
27  * `TRACE'.
28  *
29  * @author Michiel Meeuwissen
30  **/

31
32 public class Log4jLevel extends Level {
33
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(SERVICE_INT, "SERVICE", 5);
44     // DEBUG
45
public static final Log4jLevel TRACE = new Log4jLevel(TRACE_INT, "TRACE", 7);
46
47
48     protected Log4jLevel(int level, String JavaDoc strLevel, int syslogEquiv) {
49         super(level, strLevel, syslogEquiv);
50     }
51
52     public static Level toLevel(String JavaDoc sArg) {
53         if(sArg == null)
54             return Log4jLevel.TRACE;
55
56         String JavaDoc stringVal = sArg.toUpperCase();
57
58         if(stringVal.equals("TRACE")) return Log4jLevel.TRACE;
59         if(stringVal.equals("SERVICE")) return Log4jLevel.SERVICE;
60         return Level.toLevel(sArg);
61     }
62         
63     public static Level toLevel(int i) throws IllegalArgumentException JavaDoc {
64         switch(i) {
65         case TRACE_INT: return Log4jLevel.TRACE;
66         case SERVICE_INT: return Log4jLevel.SERVICE;
67         default:
68             return Level.toLevel(i);
69         }
70     }
71     
72     public static Priority[] getAllPossibleLog4jPriorities() {
73         return new Priority[] {OFF, FATAL, ERROR, WARN, INFO, SERVICE, DEBUG, TRACE};
74     }
75    
76     public static Level toLog4jLevel(String JavaDoc sArg) { // needed?
77
Level result;
78         result = Level.toLevel(sArg, null);
79         if (result != null) {
80             return result;
81         }
82         String JavaDoc s = sArg.toUpperCase();
83         if (s.equals("SERVICE")) return SERVICE;
84         if (s.equals("TRACE")) return TRACE;
85         return DEBUG;
86     }
87
88 }
89
Popular Tags