001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // Copyright (C) Nordic Wave Inc, All rights reserved
005: // $Id: OzoneDebugLevel.java,v 1.1 2002/05/17 08:55:47 per_nyfelt Exp $
006:
007: package org.ozoneDB.util;
008:
009: import org.apache.log4j.Level;
010:
011: /*
012: * Adding three finer debug levels to the Log4J Level class
013: *
014: */
015:
016: /**
017: public final static int DEBUG2_INT = 9000;
018: public final static int DEBUG3_INT = 8000;
019:
020:
021: The <code>DEBUG</code> priority designates fine-grained
022: informational events that are most useful to debug an
023: application.
024: final static public Priority DEBUG2_INT = new Level(DEBUG2_INT, "DEBUG2_INT", 7);
025: */
026: public class OzoneDebugLevel extends Level {
027:
028: static public final int DEBUG1_INT = Level.DEBUG_INT - 100;
029: static public final int DEBUG2_INT = Level.DEBUG_INT - 200;
030: static public final int DEBUG3_INT = Level.DEBUG_INT - 300;
031:
032: /* Log4j does not set these as constants in Priority, so the following ones
033: * matches those used internally by Priority */
034:
035: /** The least verbose level */
036: public static final String FATAL_STR = "FATAL";
037: /** One step finer (more verbose) than fatal */
038: public static final String ERROR_STR = "ERROR";
039: /** One step finer (more verbose) than error */
040: public static final String WARN_STR = "WARN";
041: /** One step finer (more verbose) than warn */
042: public static final String INFO_STR = "INFO";
043: /** One step finer (more verbose) than info */
044: public static final String DEBUG_STR = "DEBUG";
045:
046: /** One step finer (more verbose) than debug */
047: public static final String DEBUG1_STR = "DEBUG1";
048: /** One step finer (more verbose) than debug1 */
049: public static final String DEBUG2_STR = "DEBUG2";
050: /** One step finer (more verbose) than debug2 */
051: public static final String DEBUG3_STR = "DEBUG3";
052:
053: public static final OzoneDebugLevel DEBUG1 = new OzoneDebugLevel(
054: DEBUG1_INT, DEBUG1_STR, 7);
055: public static final OzoneDebugLevel DEBUG2 = new OzoneDebugLevel(
056: DEBUG2_INT, DEBUG2_STR, 7);
057: public static final OzoneDebugLevel DEBUG3 = new OzoneDebugLevel(
058: DEBUG3_INT, DEBUG3_STR, 7);
059:
060: protected OzoneDebugLevel(int level, String strLevel,
061: int syslogEquiv) {
062: super (level, strLevel, syslogEquiv);
063: }
064:
065: /**
066: Convert the string passed as argument to a level. If the
067: conversion fails, then this method returns {@link #DEBUG1}.
068: */
069: public static Level toLevel(String sArg) {
070: return (Level) toLevel(sArg, OzoneDebugLevel.DEBUG1);
071: }
072:
073: public static Level toLevel(String sArg, Level defaultValue) {
074:
075: if (sArg == null) {
076: return defaultValue;
077: }
078: String stringVal = sArg.toUpperCase();
079:
080: if (stringVal.equals(DEBUG1_STR)) {
081: return OzoneDebugLevel.DEBUG1;
082: } else if (stringVal.equals(DEBUG2_STR)) {
083: return OzoneDebugLevel.DEBUG2;
084: } else if (stringVal.equals(DEBUG3_STR)) {
085: return OzoneDebugLevel.DEBUG3;
086: }
087:
088: return Level.toLevel(sArg, (Level) defaultValue);
089: }
090:
091: public static Level toLevel(int i) throws IllegalArgumentException {
092: switch (i) {
093: case DEBUG1_INT:
094: return OzoneDebugLevel.DEBUG1;
095: case DEBUG2_INT:
096: return OzoneDebugLevel.DEBUG2;
097: case DEBUG3_INT:
098: return OzoneDebugLevel.DEBUG3;
099: }
100: return Level.toLevel(i);
101: }
102:
103: }
|