Source Code Cross Referenced for CommonsLoggerImpl.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » 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 » Database ORM » db ojb » org.apache.ojb.broker.util.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.broker.util.logging;
002:
003:        /* Copyright 2002-2005 The Apache Software Foundation
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:        import org.apache.commons.logging.Log;
019:        import org.apache.commons.logging.LogFactory;
020:        import org.apache.ojb.broker.util.configuration.Configuration;
021:        import org.apache.ojb.broker.util.configuration.ConfigurationException;
022:
023:        /**
024:         * This is a Logger implementation based on jakarta commons logging.
025:         * It can be enabled by putting
026:         * LoggerClass=org.apache.ojb.broker.util.logging.CommonsLoggerImpl
027:         * in the OJB .properties file. <br>
028:         * 
029:         * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
030:         * @version $Id: CommonsLoggerImpl.java,v 1.4.2.3 2005/12/21 22:28:16 tomdz Exp $
031:         */
032:        public class CommonsLoggerImpl implements  Logger {
033:            private String name;
034:            private transient Log log;
035:
036:            /**
037:             * Constructor for CommonsLoggerImpl.
038:             */
039:            public CommonsLoggerImpl(String aName) {
040:                this .name = aName;
041:            }
042:
043:            /**
044:             * Returns the log.
045:             * @return Log
046:             */
047:            public Log getLog() {
048:                /*
049:                Logger interface extends Serializable, thus Log field is
050:                declared 'transient' and we have to null-check
051:                 */
052:                if (log == null) {
053:                    log = LogFactory.getLog(name);
054:                }
055:                return log;
056:            }
057:
058:            /**
059:             * @see org.apache.ojb.broker.util.logging.Logger#isEnabledFor(int)
060:             */
061:            public boolean isEnabledFor(int priority) {
062:                Log commonsLog = getLog();
063:                switch (priority) {
064:                case Logger.DEBUG:
065:                    return commonsLog.isDebugEnabled();
066:                case Logger.INFO:
067:                    return commonsLog.isInfoEnabled();
068:                case Logger.WARN:
069:                    return commonsLog.isWarnEnabled();
070:                case Logger.ERROR:
071:                    return commonsLog.isErrorEnabled();
072:                case Logger.FATAL:
073:                    return commonsLog.isFatalEnabled();
074:                }
075:                return false;
076:            }
077:
078:            /**
079:             * @see org.apache.ojb.broker.util.logging.Logger#debug(Object)
080:             */
081:            public void debug(Object pObject) {
082:                getLog().debug(pObject);
083:            }
084:
085:            /**
086:             * @see org.apache.ojb.broker.util.logging.Logger#info(Object)
087:             */
088:            public void info(Object pObject) {
089:                getLog().info(pObject);
090:            }
091:
092:            /**
093:             * @see org.apache.ojb.broker.util.logging.Logger#warn(Object)
094:             */
095:            public void warn(Object pObject) {
096:                getLog().warn(pObject);
097:            }
098:
099:            /**
100:             * @see org.apache.ojb.broker.util.logging.Logger#error(Object)
101:             */
102:            public void error(Object pObject) {
103:                getLog().error(pObject);
104:            }
105:
106:            /**
107:             * @see org.apache.ojb.broker.util.logging.Logger#fatal(Object)
108:             */
109:            public void fatal(Object pObject) {
110:                getLog().fatal(pObject);
111:            }
112:
113:            /**
114:             * @see org.apache.ojb.broker.util.logging.Logger#debug(Object, Throwable)
115:             */
116:            public void debug(Object message, Throwable obj) {
117:                getLog().debug(message, obj);
118:            }
119:
120:            /**
121:             * @see org.apache.ojb.broker.util.logging.Logger#info(Object, Throwable)
122:             */
123:            public void info(Object message, Throwable obj) {
124:                getLog().info(message, obj);
125:            }
126:
127:            /**
128:             * @see org.apache.ojb.broker.util.logging.Logger#warn(Object, Throwable)
129:             */
130:            public void warn(Object message, Throwable obj) {
131:                getLog().warn(message, obj);
132:            }
133:
134:            /**
135:             * @see org.apache.ojb.broker.util.logging.Logger#error(Object, Throwable)
136:             */
137:            public void error(Object message, Throwable obj) {
138:                getLog().error(message, obj);
139:            }
140:
141:            /**
142:             * @see org.apache.ojb.broker.util.logging.Logger#fatal(Object, Throwable)
143:             */
144:            public void fatal(Object message, Throwable obj) {
145:                getLog().fatal(message, obj);
146:            }
147:
148:            /**
149:             * @see org.apache.ojb.broker.util.logging.Logger#isDebugEnabled()
150:             */
151:            public boolean isDebugEnabled() {
152:                return getLog().isDebugEnabled();
153:            }
154:
155:            /**
156:             * @see org.apache.ojb.broker.util.logging.Logger#getName()
157:             */
158:            public String getName() {
159:                return name;
160:            }
161:
162:            /**
163:             * @see org.apache.ojb.broker.util.logging.Logger#safeDebug(String, Object)
164:             */
165:            public void safeDebug(String message, Object obj) {
166:                if (getLog().isDebugEnabled()) {
167:                    String toString = safeToString(obj);
168:                    getLog().debug(message + " : " + toString);
169:                }
170:            }
171:
172:            /**
173:             * @see org.apache.ojb.broker.util.logging.Logger#safeDebug(String, Object, Throwable)
174:             */
175:            public void safeDebug(String message, Object obj, Throwable t) {
176:                if (getLog().isDebugEnabled()) {
177:                    String toString = safeToString(obj);
178:                    getLog().debug(message + " : " + toString, t);
179:                }
180:            }
181:
182:            /**
183:             * @see org.apache.ojb.broker.util.logging.Logger#safeInfo(String, Object)
184:             */
185:            public void safeInfo(String message, Object obj) {
186:                if (getLog().isInfoEnabled()) {
187:                    String toString = safeToString(obj);
188:                    getLog().info(message + " : " + toString);
189:                }
190:            }
191:
192:            /**
193:             * @see org.apache.ojb.broker.util.logging.Logger#safeInfo(String, Object, Throwable)
194:             */
195:            public void safeInfo(String message, Object obj, Throwable t) {
196:                if (getLog().isInfoEnabled()) {
197:                    String toString = safeToString(obj);
198:                    getLog().info(message + " : " + toString, t);
199:                }
200:            }
201:
202:            /**
203:             * @see org.apache.ojb.broker.util.logging.Logger#safeWarn(String, Object)
204:             */
205:            public void safeWarn(String message, Object obj) {
206:                if (getLog().isWarnEnabled()) {
207:                    String toString = safeToString(obj);
208:                    getLog().warn(message + " : " + toString);
209:                }
210:            }
211:
212:            /**
213:             * @see org.apache.ojb.broker.util.logging.Logger#safeWarn(String, Object, Throwable)
214:             */
215:            public void safeWarn(String message, Object obj, Throwable t) {
216:                if (getLog().isWarnEnabled()) {
217:                    String toString = safeToString(obj);
218:                    getLog().warn(message + " : " + toString, t);
219:                }
220:            }
221:
222:            /**
223:             * @see org.apache.ojb.broker.util.logging.Logger#safeError(String, Object)
224:             */
225:            public void safeError(String message, Object obj) {
226:                if (getLog().isErrorEnabled()) {
227:                    String toString = safeToString(obj);
228:                    getLog().error(message + " : " + toString);
229:                }
230:            }
231:
232:            /**
233:             * @see org.apache.ojb.broker.util.logging.Logger#safeError(String, Object, Throwable)
234:             */
235:            public void safeError(String message, Object obj, Throwable t) {
236:                if (getLog().isErrorEnabled()) {
237:                    String toString = safeToString(obj);
238:                    getLog().error(message + " : " + toString, t);
239:                }
240:            }
241:
242:            /**
243:             * @see org.apache.ojb.broker.util.logging.Logger#safeFatal(String, Object)
244:             */
245:            public void safeFatal(String message, Object obj) {
246:                if (getLog().isFatalEnabled()) {
247:                    String toString = safeToString(obj);
248:                    getLog().fatal(message + " : " + toString);
249:                }
250:            }
251:
252:            /**
253:             * @see org.apache.ojb.broker.util.logging.Logger#safeFatal(String, Object, Throwable)
254:             */
255:            public void safeFatal(String message, Object obj, Throwable t) {
256:                if (getLog().isFatalEnabled()) {
257:                    String toString = safeToString(obj);
258:                    getLog().fatal(message + " : " + toString, t);
259:                }
260:            }
261:
262:            /**
263:             * provides a safe toString
264:             */
265:            private String safeToString(Object obj) {
266:                String toString = null;
267:                if (obj != null) {
268:                    try {
269:                        toString = obj.toString();
270:                    } catch (Throwable ex) {
271:                        toString = "BAD toString() impl for "
272:                                + obj.getClass().getName();
273:                    }
274:                }
275:                return toString;
276:            }
277:
278:            /**
279:             * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
280:             */
281:            public void configure(Configuration config)
282:                    throws ConfigurationException {
283:                // do nothing
284:            }
285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.