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 "SHOUT" level from a
38: * log4j properties file must specify the full
39: * "SHOUT#org.cougaar.util.log.log4j.ShoutPriority"
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 SHOUT or higher:<pre>
44: * ...
45: * log4j.category.com.foo=SHOUT#org.cougaar.util.log.log4j.ShoutPriority
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 ShoutPriority extends Level {
55:
56: static final int SHOUT_INT = Level.ERROR_INT + 1;
57:
58: static String SHOUT_STR = "SHOUT";
59:
60: static final ShoutPriority SHOUT = new ShoutPriority(SHOUT_INT,
61: SHOUT_STR, 0);
62:
63: protected ShoutPriority(int level, String strLevel, int syslogEquiv) {
64: super (level, strLevel, syslogEquiv);
65: }
66:
67: public static Priority toPriority(String sArg, Priority defaultValue) {
68: return ((SHOUT_STR.equalsIgnoreCase(sArg)) ? (SHOUT)
69: : (Priority.toPriority(sArg, defaultValue)));
70: }
71:
72: public static Priority toPriority(int i)
73: throws IllegalArgumentException {
74: return ((i == SHOUT_INT) ? (SHOUT) : (Priority.toPriority(i)));
75: }
76:
77: public static Level toLevel(String sArg) {
78: return ((SHOUT_STR.equalsIgnoreCase(sArg)) ? (SHOUT) : (Level
79: .toLevel(sArg)));
80: }
81:
82: public static Level toLevel(int val) {
83: return ((val == SHOUT_INT) ? (SHOUT) : (Level.toLevel(val)));
84: }
85:
86: public static Level toLevel(int val, Level defaultLevel) {
87: return ((val == SHOUT_INT) ? (SHOUT) : Level.toLevel(val,
88: defaultLevel));
89: }
90:
91: public static Level toLevel(String sArg, Level defaultLevel) {
92: return ((SHOUT_STR.equalsIgnoreCase(sArg)) ? (SHOUT) : Level
93: .toLevel(sArg, defaultLevel));
94: }
95: }
|