KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > util > OzoneDebugLevel


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// Copyright (C) Nordic Wave Inc, All rights reserved
5
// $Id: OzoneDebugLevel.java,v 1.4 2002/12/29 11:15:58 per_nyfelt Exp $
6

7 package org.ozoneDB.util;
8
9 import org.apache.log4j.Level;
10
11 /**
12  * Extends Logging capability by adding three finer debug levels
13  * to the Log4J Level class.
14  * @author Per Nyfelt
15  */

16 public class OzoneDebugLevel extends Level {
17
18     static public final int DEBUG1_INT = Level.DEBUG_INT - 100;
19     static public final int DEBUG2_INT = Level.DEBUG_INT - 200;
20     static public final int DEBUG3_INT = Level.DEBUG_INT - 300;
21
22     /* Log4j does not set these as constants in Priority, so the following ones
23      * matches those used internally by Priority */

24
25     /** The least verbose level */
26     public static final String JavaDoc FATAL_STR = "FATAL";
27     /** One step finer (more verbose) than fatal */
28     public static final String JavaDoc ERROR_STR = "ERROR";
29     /** One step finer (more verbose) than error */
30     public static final String JavaDoc WARN_STR = "WARN";
31     /** One step finer (more verbose) than warn */
32     public static final String JavaDoc INFO_STR = "INFO";
33     /** One step finer (more verbose) than info */
34     public static final String JavaDoc DEBUG_STR = "DEBUG";
35
36     /** One step finer (more verbose) than debug */
37     public static final String JavaDoc DEBUG1_STR = "DEBUG1";
38     /** One step finer (more verbose) than debug1 */
39     public static final String JavaDoc DEBUG2_STR = "DEBUG2";
40     /** One step finer (more verbose) than debug2 */
41     public static final String JavaDoc DEBUG3_STR = "DEBUG3";
42
43     public static final OzoneDebugLevel DEBUG1 = new OzoneDebugLevel(DEBUG1_INT, DEBUG1_STR, 7);
44     public static final OzoneDebugLevel DEBUG2 = new OzoneDebugLevel(DEBUG2_INT, DEBUG2_STR, 7);
45     public static final OzoneDebugLevel DEBUG3 = new OzoneDebugLevel(DEBUG3_INT, DEBUG3_STR, 7);
46
47
48     protected OzoneDebugLevel(int level, String JavaDoc strLevel, int syslogEquiv) {
49         super(level, strLevel, syslogEquiv);
50     }
51
52     /**
53      Convert the string passed as argument to a level. If the
54      conversion fails, then this method returns {@link #DEBUG1}.
55      */

56     public static Level toLevel(String JavaDoc sArg) {
57         return (Level) toLevel(sArg, OzoneDebugLevel.DEBUG1);
58     }
59
60
61     public static Level toLevel(String JavaDoc sArg, Level defaultValue) {
62
63         if (sArg == null) {
64             return defaultValue;
65         }
66         String JavaDoc stringVal = sArg.toUpperCase();
67
68         if (stringVal.equals(DEBUG1_STR)) {
69             return OzoneDebugLevel.DEBUG1;
70         } else if (stringVal.equals(DEBUG2_STR)) {
71             return OzoneDebugLevel.DEBUG2;
72         } else if (stringVal.equals(DEBUG3_STR)) {
73             return OzoneDebugLevel.DEBUG3;
74         }
75
76         return Level.toLevel(sArg, (Level) defaultValue);
77     }
78
79
80     public static Level toLevel(int i) throws IllegalArgumentException JavaDoc {
81         switch (i) {
82             case DEBUG1_INT:
83                 return OzoneDebugLevel.DEBUG1;
84             case DEBUG2_INT:
85                 return OzoneDebugLevel.DEBUG2;
86             case DEBUG3_INT:
87                 return OzoneDebugLevel.DEBUG3;
88         }
89         return Level.toLevel(i);
90     }
91
92 }
93
Popular Tags