Source Code Cross Referenced for Log.java in  » Sevlet-Container » jetty-modules » org » mortbay » 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 » Sevlet Container » jetty modules » org.mortbay.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ========================================================================
002:        // Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
003:        // ------------------------------------------------------------------------
004:        // Licensed under the Apache License, Version 2.0 (the "License");
005:        // you may not use this file except in compliance with the License.
006:        // You may obtain a copy of the License at 
007:        // http://www.apache.org/licenses/LICENSE-2.0
008:        // Unless required by applicable law or agreed to in writing, software
009:        // distributed under the License is distributed on an "AS IS" BASIS,
010:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011:        // See the License for the specific language governing permissions and
012:        // limitations under the License.
013:        // ========================================================================
014:
015:        package org.mortbay.log;
016:
017:        import java.lang.reflect.Method;
018:
019:        import org.mortbay.util.Loader;
020:
021:        /*-----------------------------------------------------------------------*/
022:        /** Logging.
023:         * This class provides a static logging interface.  If an instance of the 
024:         * org.slf4j.Logger class is found on the classpath, the static log methods
025:         * are directed to a slf4j logger for "org.mortbay.log".   Otherwise the logs
026:         * are directed to stderr.
027:         * 
028:         * If the system property VERBOSE is set, then ignored exceptions are logged in detail.
029:         * 
030:         */
031:        public class Log {
032:            private static final String[] __nestedEx = { "getTargetException",
033:                    "getTargetError", "getException", "getRootCause" };
034:            /*-------------------------------------------------------------------*/
035:            private static final Class[] __noArgs = new Class[0];
036:            public final static String EXCEPTION = "EXCEPTION ";
037:            public final static String IGNORED = "IGNORED";
038:            public final static String IGNORED_FMT = "IGNORED: {}";
039:            public final static String NOT_IMPLEMENTED = "NOT IMPLEMENTED ";
040:
041:            private static String logClass = System.getProperty(
042:                    "org.mortbay.log.class", "org.mortbay.log.Slf4jLog");
043:            private static boolean verbose = System
044:                    .getProperty("VERBOSE", null) != null;
045:            private static Logger log;
046:
047:            static {
048:                Class log_class = null;
049:                try {
050:                    log_class = Loader.loadClass(Log.class, logClass);
051:                    log = (Logger) log_class.newInstance();
052:                } catch (Exception e) {
053:                    log_class = StdErrLog.class;
054:                    log = new StdErrLog();
055:                    if (verbose)
056:                        e.printStackTrace();
057:                }
058:
059:                log.info("Logging to {} via {}", log, log_class.getName());
060:            }
061:
062:            public static void setLog(Logger log) {
063:                Log.log = log;
064:            }
065:
066:            public static Logger getLog() {
067:                return log;
068:            }
069:
070:            public static void debug(Throwable th) {
071:                if (log == null)
072:                    return;
073:                log.debug(EXCEPTION, th);
074:                unwind(th);
075:            }
076:
077:            public static void debug(String msg) {
078:                if (log == null)
079:                    return;
080:                log.debug(msg, null, null);
081:            }
082:
083:            public static void debug(String msg, Object arg) {
084:                if (log == null)
085:                    return;
086:                log.debug(msg, arg, null);
087:            }
088:
089:            public static void debug(String msg, Object arg0, Object arg1) {
090:                if (log == null)
091:                    return;
092:                log.debug(msg, arg0, arg1);
093:            }
094:
095:            /* ------------------------------------------------------------ */
096:            /**
097:             * Ignore an exception unless trace is enabled.
098:             * This works around the problem that log4j does not support the trace level.
099:             */
100:            public static void ignore(Throwable th) {
101:                if (log == null)
102:                    return;
103:                if (verbose) {
104:                    log.debug(IGNORED, th);
105:                    unwind(th);
106:                }
107:            }
108:
109:            public static void info(String msg) {
110:                if (log == null)
111:                    return;
112:                log.info(msg, null, null);
113:            }
114:
115:            public static void info(String msg, Object arg) {
116:                if (log == null)
117:                    return;
118:                log.info(msg, arg, null);
119:            }
120:
121:            public static void info(String msg, Object arg0, Object arg1) {
122:                if (log == null)
123:                    return;
124:                log.info(msg, arg0, arg1);
125:            }
126:
127:            public static boolean isDebugEnabled() {
128:                if (log == null)
129:                    return false;
130:                return log.isDebugEnabled();
131:            }
132:
133:            public static void warn(String msg) {
134:                if (log == null)
135:                    return;
136:                log.warn(msg, null, null);
137:            }
138:
139:            public static void warn(String msg, Object arg) {
140:                if (log == null)
141:                    return;
142:                log.warn(msg, arg, null);
143:            }
144:
145:            public static void warn(String msg, Object arg0, Object arg1) {
146:                if (log == null)
147:                    return;
148:                log.warn(msg, arg0, arg1);
149:            }
150:
151:            public static void warn(String msg, Throwable th) {
152:                if (log == null)
153:                    return;
154:                log.warn(msg, th);
155:                unwind(th);
156:            }
157:
158:            public static void warn(Throwable th) {
159:                if (log == null)
160:                    return;
161:                log.warn(EXCEPTION, th);
162:                unwind(th);
163:            }
164:
165:            /** Obtain a named Logger.
166:             * Obtain a named Logger or the default Logger if null is passed.
167:             */
168:            public static Logger getLogger(String name) {
169:                if (log == null)
170:                    return log;
171:                if (name == null)
172:                    return log;
173:                return log.getLogger(name);
174:            }
175:
176:            private static void unwind(Throwable th) {
177:                if (th == null)
178:                    return;
179:                for (int i = 0; i < __nestedEx.length; i++) {
180:                    try {
181:                        Method get_target = th.getClass().getMethod(
182:                                __nestedEx[i], __noArgs);
183:                        Throwable th2 = (Throwable) get_target.invoke(th, null);
184:                        if (th2 != null)
185:                            warn("Nested in " + th + ":", th2);
186:                    } catch (Exception ignore) {
187:                    }
188:                }
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.