Source Code Cross Referenced for DirectJDKLog.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » juli » logging » 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 » apache tomcat 6.0.14 » org.apache.juli.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2004 The Apache Software Foundation.
003:         * Copyright 2004 Costin Manolache
004:         * 
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.juli.logging;
019:
020:        import java.util.logging.ConsoleHandler;
021:        import java.util.logging.Formatter;
022:        import java.util.logging.Handler;
023:        import java.util.logging.Level;
024:        import java.util.logging.Logger;
025:
026:        /** 
027:         * Hardcoded java.util.logging commons-logging implementation.
028:         * 
029:         * In addition, it curr 
030:         * 
031:         */
032:        class DirectJDKLog implements  Log {
033:            // no reason to hide this - but good reasons to not hide
034:            public Logger logger;
035:
036:            /** Alternate config reader and console format 
037:             */
038:            private static final String SIMPLE_FMT = "org.apache.tomcat.util.log.JdkLoggerFormatter";
039:            private static final String SIMPLE_CFG = "org.apache.tomcat.util.log.JdkLoggerConfig";
040:
041:            static {
042:                if (System.getProperty("java.util.logging.config.class") == null
043:                        && System.getProperty("java.util.logging.config.file") == null) {
044:                    // default configuration - it sucks. Let's override at least the 
045:                    // formatter for the console
046:                    try {
047:                        Class.forName(SIMPLE_CFG).newInstance();
048:                    } catch (Throwable t) {
049:                    }
050:                    try {
051:                        Formatter fmt = (Formatter) Class.forName(SIMPLE_FMT)
052:                                .newInstance();
053:                        // it is also possible that the user modifed jre/lib/logging.properties - 
054:                        // but that's really stupid in most cases
055:                        Logger root = Logger.getLogger("");
056:                        Handler handlers[] = root.getHandlers();
057:                        for (int i = 0; i < handlers.length; i++) {
058:                            // I only care about console - that's what's used in default config anyway
059:                            if (handlers[i] instanceof  ConsoleHandler) {
060:                                handlers[i].setFormatter(fmt);
061:                            }
062:                        }
063:                    } catch (Throwable t) {
064:                        // maybe it wasn't included - the ugly default will be used.
065:                    }
066:
067:                }
068:            }
069:
070:            public DirectJDKLog(String name) {
071:                logger = Logger.getLogger(name);
072:            }
073:
074:            public final boolean isErrorEnabled() {
075:                return logger.isLoggable(Level.SEVERE);
076:            }
077:
078:            public final boolean isWarnEnabled() {
079:                return logger.isLoggable(Level.WARNING);
080:            }
081:
082:            public final boolean isInfoEnabled() {
083:                return logger.isLoggable(Level.INFO);
084:            }
085:
086:            public final boolean isDebugEnabled() {
087:                return logger.isLoggable(Level.FINE);
088:            }
089:
090:            public final boolean isFatalEnabled() {
091:                return logger.isLoggable(Level.SEVERE);
092:            }
093:
094:            public final boolean isTraceEnabled() {
095:                return logger.isLoggable(Level.FINER);
096:            }
097:
098:            public final void debug(Object message) {
099:                log(Level.FINE, String.valueOf(message), null);
100:            }
101:
102:            public final void debug(Object message, Throwable t) {
103:                log(Level.FINE, String.valueOf(message), t);
104:            }
105:
106:            public final void trace(Object message) {
107:                log(Level.FINER, String.valueOf(message), null);
108:            }
109:
110:            public final void trace(Object message, Throwable t) {
111:                log(Level.FINER, String.valueOf(message), t);
112:            }
113:
114:            public final void info(Object message) {
115:                log(Level.INFO, String.valueOf(message), null);
116:            }
117:
118:            public final void info(Object message, Throwable t) {
119:                log(Level.INFO, String.valueOf(message), t);
120:            }
121:
122:            public final void warn(Object message) {
123:                log(Level.WARNING, String.valueOf(message), null);
124:            }
125:
126:            public final void warn(Object message, Throwable t) {
127:                log(Level.WARNING, String.valueOf(message), t);
128:            }
129:
130:            public final void error(Object message) {
131:                log(Level.SEVERE, String.valueOf(message), null);
132:            }
133:
134:            public final void error(Object message, Throwable t) {
135:                log(Level.SEVERE, String.valueOf(message), t);
136:            }
137:
138:            public final void fatal(Object message) {
139:                log(Level.SEVERE, String.valueOf(message), null);
140:            }
141:
142:            public final void fatal(Object message, Throwable t) {
143:                log(Level.SEVERE, String.valueOf(message), t);
144:            }
145:
146:            // from commons logging. This would be my number one reason why java.util.logging
147:            // is bad - design by comitee can be really bad ! The impact on performance of 
148:            // using java.util.logging - and the ugliness if you need to wrap it - is far
149:            // worse than the unfriendly and uncommon default format for logs. 
150:
151:            private void log(Level level, String msg, Throwable ex) {
152:                if (logger.isLoggable(level)) {
153:                    // Hack (?) to get the stack trace.
154:                    Throwable dummyException = new Throwable();
155:                    StackTraceElement locations[] = dummyException
156:                            .getStackTrace();
157:                    // Caller will be the third element
158:                    String cname = "unknown";
159:                    String method = "unknown";
160:                    if (locations != null && locations.length > 2) {
161:                        StackTraceElement caller = locations[2];
162:                        cname = caller.getClassName();
163:                        method = caller.getMethodName();
164:                    }
165:                    if (ex == null) {
166:                        logger.logp(level, cname, method, msg);
167:                    } else {
168:                        logger.logp(level, cname, method, msg, ex);
169:                    }
170:                }
171:            }
172:
173:            // for LogFactory
174:            static void release() {
175:
176:            }
177:
178:            static Log getInstance(String name) {
179:                return new DirectJDKLog(name);
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.