001: /**
002: *
003: * Copyright (C) 2000-2004 Enterprise Distributed Technologies Ltd
004: *
005: * www.enterprisedt.com
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Bug fixes, suggestions and comments should be sent to bruce@enterprisedt.com
022: *
023: * Change Log:
024: *
025: * $Log: Level.java,v $
026: * Revision 1.8 2007-07-05 05:19:40 bruceb
027: * make getLevel() public
028: *
029: * Revision 1.7 2006/10/11 08:43:54 hans
030: * made cvsId and all the static Level declarations final
031: *
032: * Revision 1.6 2005/02/04 12:20:37 bruceb
033: * made getLevel public
034: *
035: * Revision 1.5 2004/08/31 13:54:49 bruceb
036: * remove compile warnings
037: *
038: * Revision 1.4 2004/08/16 21:08:08 bruceb
039: * made cvsids public
040: *
041: * Revision 1.3 2004/06/25 11:52:26 bruceb
042: * fixed logging bug
043: *
044: * Revision 1.2 2004/05/08 21:14:20 bruceb
045: * string -> level
046: *
047: * Revision 1.1 2004/05/01 16:55:42 bruceb
048: * first cut
049: *
050: *
051: */package com.enterprisedt.util.debug;
052:
053: /**
054: * Simple debug level class. Uses the same interface (but
055: * not implementation) as log4j, so that the debug
056: * classes could be easily replaced by log4j (by changing
057: * imports - too dangerous to rely on class path and using
058: * the same package names)
059: *
060: * @author Bruce Blackshaw
061: * @version $Revision: 1.8 $
062: */
063: public class Level {
064:
065: /**
066: * Revision control id
067: */
068: final public static String cvsId = "@(#)$Id: Level.java,v 1.8 2007-07-05 05:19:40 bruceb Exp $";
069:
070: final static int OFF_INT = -1;
071:
072: final private static String OFF_STR = "OFF";
073:
074: final static int FATAL_INT = 0;
075:
076: final private static String FATAL_STR = "FATAL";
077:
078: final static int ERROR_INT = 1;
079:
080: final private static String ERROR_STR = "ERROR";
081:
082: final static int WARN_INT = 2;
083:
084: final private static String WARN_STR = "WARN";
085:
086: final static int INFO_INT = 3;
087:
088: final private static String INFO_STR = "INFO";
089:
090: final static int DEBUG_INT = 4;
091:
092: final private static String DEBUG_STR = "DEBUG";
093:
094: final static int ALL_INT = 10;
095:
096: final private static String ALL_STR = "ALL";
097:
098: final static int LEVEL_COUNT = 5;
099:
100: /**
101: * Off level
102: */
103: final public static Level OFF = new Level(OFF_INT, OFF_STR);
104:
105: /**
106: * Fatal level
107: */
108: final public static Level FATAL = new Level(FATAL_INT, FATAL_STR);
109:
110: /**
111: * OFF level
112: */
113: final public static Level ERROR = new Level(ERROR_INT, ERROR_STR);
114:
115: /**
116: * Warn level
117: */
118: final public static Level WARN = new Level(WARN_INT, WARN_STR);
119:
120: /**
121: * Info level
122: */
123: final public static Level INFO = new Level(INFO_INT, INFO_STR);
124:
125: /**
126: * Debug level
127: */
128: final public static Level DEBUG = new Level(DEBUG_INT, DEBUG_STR);
129:
130: /**
131: * All level
132: */
133: final public static Level ALL = new Level(ALL_INT, ALL_STR);
134:
135: /**
136: * The level's integer value
137: */
138: private int level = OFF_INT;
139:
140: /**
141: * The level's string representation
142: */
143: private String string;
144:
145: /**
146: * Private constructor so no-one outside the class can
147: * create any more instances
148: *
149: * @param level level to set this instance at
150: * @param string string representation
151: */
152: private Level(int level, String string) {
153: this .level = level;
154: this .string = string;
155: }
156:
157: /**
158: * Get integer log level
159: *
160: * @return log level
161: */
162: public int getLevel() {
163: return level;
164: }
165:
166: /**
167: * Is this level greater or equal to the supplied level
168: *
169: * @param l level to test against
170: * @return true if greater or equal to, false if less than
171: */
172: boolean isGreaterOrEqual(Level l) {
173: if (this .level >= l.level)
174: return true;
175: return false;
176: }
177:
178: /**
179: * Get level from supplied string
180: *
181: * @param level level as a string
182: * @return level object or null if not found
183: */
184: public static Level getLevel(String level) {
185: if (OFF.toString().equalsIgnoreCase(level))
186: return OFF;
187: if (FATAL.toString().equalsIgnoreCase(level))
188: return FATAL;
189: if (ERROR.toString().equalsIgnoreCase(level))
190: return ERROR;
191: if (WARN.toString().equalsIgnoreCase(level))
192: return WARN;
193: if (INFO.toString().equalsIgnoreCase(level))
194: return INFO;
195: if (DEBUG.toString().equalsIgnoreCase(level))
196: return DEBUG;
197: if (ALL.toString().equalsIgnoreCase(level))
198: return ALL;
199: return null;
200: }
201:
202: /**
203: * String representation
204: *
205: * @return string
206: */
207: public String toString() {
208: return string;
209: }
210:
211: }
|