Source Code Cross Referenced for Logger.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » util » 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 » Library » Apache beehive 1.0.2 src » org.apache.beehive.netui.util.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  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:         * $Header:$
018:         */
019:        package org.apache.beehive.netui.util.logging;
020:
021:        import java.io.PrintWriter;
022:        import java.io.StringWriter;
023:        import java.lang.reflect.Method;
024:
025:        import org.apache.commons.logging.Log;
026:
027:        /**
028:         * <p>
029:         * Logging abstraction for NetUI.  This class leverages Jakarta commons-logging to create
030:         * loggers for NetUI messages.  Application developers can provide their own logger
031:         * implementations by following the instructions for creating new Log / LogFactory instances
032:         * in commons-logging.
033:         * </p>
034:         */
035:        public class Logger implements  Log {
036:
037:            /**
038:             * Factory method for creating NetUI Logger instances.
039:             *
040:             * @param loggerClient the class whose logger to create
041:             * @return a {@link Logger} instance for the given class
042:             */
043:            public static Logger getInstance(Class loggerClient) {
044:                return new Logger(org.apache.commons.logging.LogFactory
045:                        .getLog(loggerClient.getName()));
046:            }
047:
048:            private Log _logDelegate = null;
049:
050:            /**
051:             * Constructor that returns a Log4J logger.  This method is deprecated
052:             * in favor of using commons-logging to do logger creation via the
053:             * {@link #getInstance(Class)} method.
054:             *
055:             * @deprecated
056:             * @see #getInstance(Class)
057:             * @param clientClass
058:             */
059:            public Logger(Class clientClass) {
060:                _logDelegate = createDefaultLogger(clientClass);
061:            }
062:
063:            /**
064:             * Constructor that returns a Log4J logger.  This method is deprecated
065:             * in favor of using commons-logging to do logger creation via the
066:             * {@link #getInstance(Class)} method.
067:             *
068:             * @deprecated
069:             * @see #getInstance(Class)
070:             * @param clientClassName
071:             */
072:            public Logger(String clientClassName) {
073:                Class clientClass = null;
074:                try {
075:                    /* create a default log4j logger -- this shouldn't throw a CNF exception */
076:                    clientClass = Class.forName(clientClassName);
077:                } catch (ClassNotFoundException e) {
078:                    throw new IllegalArgumentException(
079:                            "Could not load NetUI logger client class '"
080:                                    + clientClassName + "'");
081:                }
082:                _logDelegate = createDefaultLogger(clientClass);
083:            }
084:
085:            /**
086:             * Internal method used by the factory to create a Logger instance.
087:             *
088:             * @param logDelegate the commons-logging {@link Log} to which messages should be logged
089:             */
090:            private Logger(Log logDelegate) {
091:                _logDelegate = logDelegate;
092:            }
093:
094:            public boolean isDebugEnabled() {
095:                return _logDelegate.isDebugEnabled();
096:            }
097:
098:            public boolean isErrorEnabled() {
099:                return _logDelegate.isErrorEnabled();
100:            }
101:
102:            public boolean isFatalEnabled() {
103:                return _logDelegate.isFatalEnabled();
104:            }
105:
106:            public boolean isInfoEnabled() {
107:                return _logDelegate.isInfoEnabled();
108:            }
109:
110:            public boolean isTraceEnabled() {
111:                return _logDelegate.isTraceEnabled();
112:            }
113:
114:            public boolean isWarnEnabled() {
115:                return _logDelegate.isWarnEnabled();
116:            }
117:
118:            public void debug(Object message) {
119:                if (isDebugEnabled())
120:                    _logDelegate.debug(message);
121:            }
122:
123:            public void debug(Object message, Throwable t) {
124:                if (isDebugEnabled())
125:                    _logDelegate.debug(format(message, t));
126:            }
127:
128:            public void trace(Object message) {
129:                if (isTraceEnabled())
130:                    _logDelegate.trace(message);
131:            }
132:
133:            public void trace(Object message, Throwable t) {
134:                if (isTraceEnabled())
135:                    _logDelegate.trace(format(message, t));
136:            }
137:
138:            public void info(Object message) {
139:                if (isInfoEnabled())
140:                    _logDelegate.info(message);
141:            }
142:
143:            public void info(Object message, Throwable t) {
144:                if (isInfoEnabled())
145:                    _logDelegate.info(format(message, t));
146:            }
147:
148:            public void warn(Object message) {
149:                if (isWarnEnabled())
150:                    _logDelegate.warn(message);
151:            }
152:
153:            public void warn(Object message, Throwable t) {
154:                if (isWarnEnabled())
155:                    _logDelegate.warn(format(message, t));
156:            }
157:
158:            public void error(Object message) {
159:                if (isErrorEnabled())
160:                    _logDelegate.error(message);
161:            }
162:
163:            public void error(Object message, Throwable t) {
164:                if (isErrorEnabled())
165:                    _logDelegate.error(format(message, t));
166:            }
167:
168:            public void fatal(Object message) {
169:                if (isFatalEnabled())
170:                    _logDelegate.fatal(message);
171:            }
172:
173:            public void fatal(Object message, Throwable t) {
174:                if (isFatalEnabled())
175:                    _logDelegate.fatal(format(message, t));
176:            }
177:
178:            private String format(Object m, Throwable t) {
179:                if (t == null)
180:                    return m.toString();
181:
182:                StringWriter sw = new StringWriter();
183:                t.printStackTrace(new PrintWriter(sw));
184:
185:                /* note, no reason to close a StringWriter */
186:
187:                return m + "\n\n" + "Throwable: " + t.toString()
188:                        + "\nStack Trace:\n" + sw.toString();
189:            }
190:
191:            /**
192:             * Internal method used to create the backwards-compat NetUI logger.  This method
193:             * looks up the {@link org.apache.beehive.netui.util.logging.internal.Log4JLogger}
194:             * and creates a new instance returning the resulting {@link Log}.
195:             *
196:             * @param loggerClient the logger client
197:             * @return the {@link Log} instance
198:             */
199:            private static final Log createDefaultLogger(Class loggerClient) {
200:                assert loggerClient != null : "Received a null loggerClient Class";
201:
202:                String className = "org.apache.beehive.netui.util.logging.internal.Log4JLogger";
203:                try {
204:                    Class logDelegateClass = Logger.class.getClassLoader()
205:                            .loadClass(className);
206:                    Method method = logDelegateClass.getMethod("getInstance",
207:                            new Class[] { Class.class });
208:                    return (Log) method.invoke(null,
209:                            new Object[] { loggerClient });
210:                } catch (Exception e) {
211:                    throw new IllegalStateException(
212:                            "Could not create log implementation '" + className
213:                                    + "' for client of type '"
214:                                    + loggerClient.getName() + "'", e);
215:                }
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.