01: /*
02: * <copyright>
03: *
04: * Copyright 2001-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.util.log.log4j;
28:
29: import org.apache.log4j.Level;
30: import org.apache.log4j.Priority;
31:
32: /**
33: * Logging level that is higher than error but less than
34: * fatal, which is used for information messages that should
35: * rarely be filtered.
36: * <p>
37: * <b>NOTE:</b> a reference to the "DETAIL" level from a
38: * log4j properties file must specify the full
39: * "DETAIL#org.cougaar.util.log.log4j.DetailPriority"
40: * line, otherwise log4j doesn't know this class and will
41: * default the level to "DEBUG".
42: * <p>
43: * For example, so set "com.foo.*" to DETAIL or higher:<pre>
44: * ...
45: * log4j.category.com.foo=DETAIL#org.cougaar.util.log.log4j.DetailPriority
46: * ...
47: * </pre>
48: * Other levels do not need this "#.." suffix, e.g.:<pre>
49: * ...
50: * log4j.category.com.foo=INFO
51: * ...
52: * </pre>
53: */
54: public class DetailPriority extends Level {
55:
56: static final int DETAIL_INT = Level.DEBUG_INT - 1;
57:
58: static String DETAIL_STR = "DETAIL";
59:
60: static final DetailPriority DETAIL = new DetailPriority(DETAIL_INT,
61: DETAIL_STR, 0);
62:
63: protected DetailPriority(int level, String strLevel, int syslogEquiv) {
64: super (level, strLevel, syslogEquiv);
65: }
66:
67: public static Priority toPriority(String sArg, Priority defaultValue) {
68: return ((DETAIL_STR.equalsIgnoreCase(sArg)) ? (DETAIL)
69: : (Priority.toPriority(sArg, defaultValue)));
70: }
71:
72: public static Priority toPriority(int i)
73: throws IllegalArgumentException {
74: return ((i == DETAIL_INT) ? (DETAIL) : (Priority.toPriority(i)));
75: }
76:
77: public static Level toLevel(String sArg) {
78: return ((DETAIL_STR.equalsIgnoreCase(sArg)) ? (DETAIL) : (Level
79: .toLevel(sArg)));
80: }
81:
82: public static Level toLevel(int val) {
83: return ((val == DETAIL_INT) ? (DETAIL) : (Level.toLevel(val)));
84: }
85:
86: public static Level toLevel(int val, Level defaultLevel) {
87: return ((val == DETAIL_INT) ? (DETAIL) : Level.toLevel(val,
88: defaultLevel));
89: }
90:
91: public static Level toLevel(String sArg, Level defaultLevel) {
92: return ((DETAIL_STR.equalsIgnoreCase(sArg)) ? (DETAIL) : Level
93: .toLevel(sArg, defaultLevel));
94: }
95: }
|