01: // $Id: Logging.java,v 1.3.2.1 2007/09/27 19:13:34 twright Exp $
02: /*
03:
04: * <copyright>
05: *
06: * Copyright 2002-2007 BBNT Solutions, LLC
07: * under sponsorship of the Defense Advanced Research Projects
08: * Agency (DARPA).
09: *
10: * You can redistribute this software and/or modify it under the
11: * terms of the Cougaar Open Source License as published on the
12: * Cougaar Open Source Website (www.cougaar.org).
13: *
14: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: *
26: * </copyright>
27:
28: */
29:
30: package org.cougaar.qos.qrs;
31:
32: import java.util.HashMap;
33: import java.util.Map;
34:
35: import org.cougaar.util.log.Logger;
36:
37: public class Logging {
38: private static String dprefix = null;
39: private static String eprefix = null;
40: private static String junk_prefix = null;
41:
42: private static Map<Class<?>, Logger> loggers = new HashMap<Class<?>, Logger>();
43: private static Map<Class<?>, Logger> eventLoggers = new HashMap<Class<?>, Logger>();
44:
45: public static void configure(String debugPrefix,
46: String eventPrefix, String junkPrefix) {
47: dprefix = debugPrefix;
48: eprefix = eventPrefix;
49: junk_prefix = junkPrefix;
50: }
51:
52: private static String hack_classname(String prefix, Class<?> klass) {
53: String classname = klass.getName();
54: if (junk_prefix != null && classname.startsWith(junk_prefix)) {
55: classname = classname.substring(junk_prefix.length());
56: }
57: if (prefix != null) {
58: return prefix + classname;
59: } else {
60: return classname;
61: }
62: }
63:
64: public static Logger getLogger(Class<?> klass) {
65: Logger result;
66: synchronized (loggers) {
67: result = loggers.get(klass);
68: if (result == null) {
69: String tag = hack_classname(dprefix, klass);
70: result = org.cougaar.util.log.Logging.getLogger(tag);
71: loggers.put(klass, result);
72: }
73: }
74: return result;
75: }
76:
77: public static Logger getEventLogger(Class<?> klass) {
78: Logger result;
79: synchronized (eventLoggers) {
80: result = eventLoggers.get(klass);
81: if (result == null) {
82: String tag = hack_classname(eprefix, klass);
83: result = org.cougaar.util.log.Logging.getLogger(tag);
84: eventLoggers.put(klass, result);
85: }
86: }
87: return result;
88: }
89:
90: }
|