Source Code Cross Referenced for Logging.java in  » Science » Cougaar12_4 » org » cougaar » util » log » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.util.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2001-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.util.log;
028:
029:        import java.util.Map;
030:        import java.util.WeakHashMap;
031:
032:        /** 
033:         * Static access to simple logging facilities.
034:         * <p>
035:         * Cougaar components may be better served by using org.cougaar.core.service.LoggingService LoggingService
036:         */
037:        public final class Logging {
038:            private static Logger dotLogger = null;
039:
040:            // cannot be instantiated
041:            private Logging() {
042:            }
043:
044:            /** Alias for {@link LoggerFactory#getInstance()} **/
045:            public static LoggerFactory getLoggerFactory() {
046:                return LoggerFactory.getInstance();
047:            }
048:
049:            /** The cache for getLogger() **/
050:            private static Map loggerCache = new WeakHashMap(11);
051:
052:            /** Similar in function to <pre>
053:             *   LoggerFactory.getInstance().createLogger(name);
054:             * <pre>
055:             * except that this accessor memoizes the calls to 
056:             * reduce memory load.
057:             **/
058:            public static Logger getLogger(Object name) {
059:                synchronized (loggerCache) {
060:                    String key = getKey(name);
061:                    Logger l = (Logger) loggerCache.get(key);
062:                    if (l == null) {
063:                        // used to use createLogger, but that has been ruined by misuse
064:                        l = LoggerFactory.getInstance().newLogger(name);
065:                        // store the key as a new string instance to 
066:                        // make sure it is collectable.
067:                        loggerCache.put(new String(key), l);
068:                    }
069:                    return l;
070:                }
071:            }
072:
073:            public static void printDot(String dot) {
074:                synchronized (Logging.class) {
075:                    if (dotLogger == null) {
076:                        dotLogger = getLogger("DOTS");
077:                    }
078:                }
079:                dotLogger.printDot(dot);
080:            }
081:
082:            /** The cache for getLoggerController() **/
083:            private static Map lcCache = new WeakHashMap(11);
084:
085:            /** Similar in function to <pre>
086:             *   LoggerFactory.getInstance().createLoggerController(name);
087:             * <pre>
088:             * except that this accessor memoizes the calls to 
089:             * reduce memory load.
090:             **/
091:            public static LoggerController getLoggerController(Object name) {
092:                synchronized (lcCache) {
093:                    String key = getKey(name);
094:                    LoggerController lc = (LoggerController) lcCache.get(key);
095:                    if (lc == null) {
096:                        lc = LoggerFactory.getInstance()
097:                                .createLoggerController(key);
098:                        // store the key as a new string instance to 
099:                        // make sure it is collectable.
100:                        lcCache.put(new String(key), lc);
101:                    }
102:                    return lc;
103:                }
104:            }
105:
106:            /** store for defaultLogger(), guarded by syncing on the class **/
107:            private static Logger defaultLogger = null;
108:
109:            /** Returns the default Logger instance - the value returned by {@link #currentLogger()}
110:             * if there is no active context.
111:             **/
112:            public synchronized static Logger defaultLogger() {
113:                if (defaultLogger == null) {
114:                    defaultLogger = getLogger("Default");
115:                }
116:                return defaultLogger;
117:            }
118:
119:            /** Store for withLogger and currentLogger **/
120:            private static final ThreadLocal loggerContext = new ThreadLocal();
121:
122:            /** Call a runnable in the dynamic context of a particular logger.
123:             * Anyone within that context can call {@link #currentLogger()}
124:             * to get access to an appropriate logger instance.
125:             * If no such instance has been installed, will use a generic 
126:             * logger with the name "Default".  This value may be retrieved
127:             * by calling {@link #defaultLogger()}.
128:             * @note withLogger may be called recursively, as the Logger contexts are
129:             * allowed to nest.
130:             * @note Child threads do not inherit Logger contexts.
131:             **/
132:            public static void withLogger(Logger l, Runnable r) {
133:                Logger old = (Logger) loggerContext.get();
134:                try {
135:                    loggerContext.set(l);
136:                    r.run();
137:                } finally {
138:                    loggerContext.set(old);
139:                }
140:            }
141:
142:            /** Return the Logger currently in-force in the current thread, as set
143:             * by {@link #withLogger(Logger,Runnable)}.
144:             * @return the current logger or the value returned by defaultLogger().  This method will
145:             * never return null.
146:             * @see #hasLogger()
147:             * @note Child threads do not inherit Logger contexts.
148:             **/
149:            public static Logger currentLogger() {
150:                Logger l = (Logger) loggerContext.get();
151:                if (l == null) {
152:                    l = defaultLogger();
153:                }
154:                return l;
155:            }
156:
157:            /** Is there a Logger in-force for the current thread?
158:             * @return true IFF currentLogger would return something other than the default logger.
159:             **/
160:            public static boolean hasLogger() {
161:                Logger l = (Logger) loggerContext.get();
162:                return (l != null);
163:            }
164:
165:            //
166:            // private utilities
167:            // 
168:
169:            /** Compute the Logging Name of the referenced object.
170:             * Used by various objects which can create Logger instances.
171:             **/
172:            public static final String getKey(Object x) {
173:                if (x instanceof  Class) {
174:                    return ((Class) x).getName();
175:                } else if (x instanceof  String) {
176:                    return (String) x;
177:                } else if (x == null) {
178:                    return "null";
179:                } else {
180:                    return x.getClass().getName();
181:                }
182:            }
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.