PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/apache-log4j-1.2.17/examples/customLevel/XLevel.java

#
Java | 90 lines | 44 code | 21 blank | 25 comment | 5 complexity | aac76072fcf53af1403564b296a58470 MD5 | raw file
Possible License(s): Apache-2.0
 1/*
 2 * Licensed to the Apache Software Foundation (ASF) under one or more
 3 * contributor license agreements.  See the NOTICE file distributed with
 4 * this work for additional information regarding copyright ownership.
 5 * The ASF licenses this file to You under the Apache License, Version 2.0
 6 * (the "License"); you may not use this file except in compliance with
 7 * the License.  You may obtain a copy of the License at
 8 * 
 9 *      http://www.apache.org/licenses/LICENSE-2.0
10 * 
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package examples.customLevel;
19
20import org.apache.log4j.Level;
21
22
23/**
24   This class introduces a new level level called TRACE. TRACE has
25   lower level than DEBUG.
26
27 */
28public class XLevel extends Level {
29  private static final long serialVersionUID = 2626753561969426769L;
30
31  static public final int  TRACE_INT   = Level.DEBUG_INT - 1;
32  static public final int  LETHAL_INT  = Level.FATAL_INT + 1;
33
34
35  private static String TRACE_STR  = "TRACE";
36  private static String LETHAL_STR  = "LETHAL";
37
38
39  public static final XLevel TRACE = new XLevel(TRACE_INT, TRACE_STR, 7);
40  public static final XLevel LETHAL = new XLevel(LETHAL_INT, LETHAL_STR, 
41						       0);
42
43
44  protected
45  XLevel(int level, String strLevel, int syslogEquiv) {
46    super(level, strLevel, syslogEquiv);
47  }
48
49  /**
50     Convert the string passed as argument to a level. If the
51     conversion fails, then this method returns {@link #TRACE}. 
52  */
53  public
54  static
55  Level toLevel(String sArg) {
56    return (Level) toLevel(sArg, XLevel.TRACE);
57  }
58
59
60  public
61  static
62  Level toLevel(String sArg, Level defaultValue) {
63
64    if(sArg == null) {
65      return defaultValue;
66    }
67    String stringVal = sArg.toUpperCase();
68    
69    if(stringVal.equals(TRACE_STR)) {
70      return XLevel.TRACE;
71    } else if(stringVal.equals(LETHAL_STR)) {
72      return XLevel.LETHAL;
73    }
74      
75    return Level.toLevel(sArg, (Level) defaultValue);    
76  }
77
78
79  public
80  static
81  Level toLevel(int i) throws  IllegalArgumentException {
82    switch(i) {
83    case TRACE_INT: return XLevel.TRACE;
84    case LETHAL_INT: return XLevel.LETHAL;
85    }
86    return Level.toLevel(i);
87  }
88
89}
90