1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.log4j.ext;
22
23
24
25
26
27
28
29
30
31
32 import org.apache.log4j.Level;
33 import org.apache.log4j.spi.LoggingEvent;
34
35 /***
36 * TODO Add docs
37 *
38 * @author michaellif
39 * @version $Revision: 1.1 $ ($Author: mishalifschitz $)
40 */
41 public class Monitor extends Level {
42
43 /***
44 * MONITOR level integer value.
45 */
46 static public final int MONITOR_INT = Level.INFO_INT - 99;
47
48 private static String MONITOR_STR = "MONITOR";
49
50 public static final Monitor MONITOR = new Monitor(MONITOR_INT, MONITOR_STR, 7);
51
52 protected Monitor(int level, String strLevel, int syslogEquiv) {
53 super(level, strLevel, syslogEquiv);
54 }
55
56 /***
57 * Convert the String argument to a level. If the conversion fails then this method returns
58 * {@link #MONITOR}.
59 */
60 public static Level toLevel(String sArg) {
61 return (Level) toLevel(sArg, Monitor.MONITOR);
62 }
63
64 /***
65 * Convert the String argument to a level. If the conversion fails, return the level specified
66 * by the second argument, i.e. defaultValue.
67 */
68 public static Level toLevel(String sArg, Level defaultValue) {
69 if (sArg == null) {
70 return defaultValue;
71 }
72 String stringVal = sArg.toUpperCase();
73 if (stringVal.equals(MONITOR_STR)) {
74 return Monitor.MONITOR;
75 }
76 return Level.toLevel(sArg, (Level) defaultValue);
77 }
78
79 /***
80 * Convert an integer passed as argument to a level. If the conversion fails, then this method
81 * returns {@link #DEBUG}.
82 */
83 public static Level toLevel(int i) throws IllegalArgumentException {
84 if (i == MONITOR_INT) {
85 return Monitor.MONITOR;
86 } else {
87 return Level.toLevel(i);
88 }
89 }
90 }