View Javadoc

1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.log4j.ext;
22  
23  /*
24   * Created on Nov 19, 2004
25   *
26   * Contributing Author(s):
27   *
28   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
29   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
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  }