Source Code Cross Referenced for StandardLogger.java in  » Database-JDBC-Connection-Pool » mysql-connector-java-5.1.3 » com » mysql » jdbc » 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 » Database JDBC Connection Pool » mysql connector java 5.1.3 » com.mysql.jdbc.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         Copyright (C) 2002-2004 MySQL AB
003:
004:         This program is free software; you can redistribute it and/or modify
005:         it under the terms of version 2 of the GNU General Public License as 
006:         published by the Free Software Foundation.
007:
008:         There are special exceptions to the terms and conditions of the GPL 
009:         as it is applied to this software. View the full text of the 
010:         exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
011:         software distribution.
012:
013:         This program is distributed in the hope that it will be useful,
014:         but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         GNU General Public License for more details.
017:
018:         You should have received a copy of the GNU General Public License
019:         along with this program; if not, write to the Free Software
020:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
021:
022:
023:
024:         */
025:        package com.mysql.jdbc.log;
026:
027:        import com.mysql.jdbc.Util;
028:        import com.mysql.jdbc.profiler.ProfilerEvent;
029:
030:        import java.util.Date;
031:
032:        /**
033:         * Provides logging facilities for those platforms that don't have built-in
034:         * facilities. Simply logs messages to STDERR.
035:         * 
036:         * @author Mark Matthews
037:         * 
038:         * @version $Id: StandardLogger.java 4597 2005-11-22 21:13:51Z mmatthews $
039:         */
040:        public class StandardLogger implements  Log {
041:            private static final int FATAL = 0;
042:
043:            private static final int ERROR = 1;
044:
045:            private static final int WARN = 2;
046:
047:            private static final int INFO = 3;
048:
049:            private static final int DEBUG = 4;
050:
051:            private static final int TRACE = 5;
052:
053:            public static StringBuffer bufferedLog = null;
054:
055:            private boolean logLocationInfo = true;
056:
057:            /**
058:             * Creates a new StandardLogger object.
059:             * 
060:             * @param name
061:             *            the name of the configuration to use -- ignored
062:             */
063:            public StandardLogger(String name) {
064:                this (name, false);
065:            }
066:
067:            public StandardLogger(String name, boolean logLocationInfo) {
068:                this .logLocationInfo = logLocationInfo;
069:            }
070:
071:            public static void saveLogsToBuffer() {
072:                if (bufferedLog == null) {
073:                    bufferedLog = new StringBuffer();
074:                }
075:            }
076:
077:            /**
078:             * @see com.mysql.jdbc.log.Log#isDebugEnabled()
079:             */
080:            public boolean isDebugEnabled() {
081:                return true;
082:            }
083:
084:            /**
085:             * @see com.mysql.jdbc.log.Log#isErrorEnabled()
086:             */
087:            public boolean isErrorEnabled() {
088:                return true;
089:            }
090:
091:            /**
092:             * @see com.mysql.jdbc.log.Log#isFatalEnabled()
093:             */
094:            public boolean isFatalEnabled() {
095:                return true;
096:            }
097:
098:            /**
099:             * @see com.mysql.jdbc.log.Log#isInfoEnabled()
100:             */
101:            public boolean isInfoEnabled() {
102:                return true;
103:            }
104:
105:            /**
106:             * @see com.mysql.jdbc.log.Log#isTraceEnabled()
107:             */
108:            public boolean isTraceEnabled() {
109:                return true;
110:            }
111:
112:            /**
113:             * @see com.mysql.jdbc.log.Log#isWarnEnabled()
114:             */
115:            public boolean isWarnEnabled() {
116:                return true;
117:            }
118:
119:            /**
120:             * Logs the given message instance using the 'debug' level
121:             * 
122:             * @param message
123:             *            the message to log
124:             */
125:            public void logDebug(Object message) {
126:                logInternal(DEBUG, message, null);
127:            }
128:
129:            /**
130:             * Logs the given message and Throwable at the 'debug' level.
131:             * 
132:             * @param message
133:             *            the message to log
134:             * @param exception
135:             *            the throwable to log (may be null)
136:             */
137:            public void logDebug(Object message, Throwable exception) {
138:                logInternal(DEBUG, message, exception);
139:            }
140:
141:            /**
142:             * Logs the given message instance using the 'error' level
143:             * 
144:             * @param message
145:             *            the message to log
146:             */
147:            public void logError(Object message) {
148:                logInternal(ERROR, message, null);
149:            }
150:
151:            /**
152:             * Logs the given message and Throwable at the 'error' level.
153:             * 
154:             * @param message
155:             *            the message to log
156:             * @param exception
157:             *            the throwable to log (may be null)
158:             */
159:            public void logError(Object message, Throwable exception) {
160:                logInternal(ERROR, message, exception);
161:            }
162:
163:            /**
164:             * Logs the given message instance using the 'fatal' level
165:             * 
166:             * @param message
167:             *            the message to log
168:             */
169:            public void logFatal(Object message) {
170:                logInternal(FATAL, message, null);
171:            }
172:
173:            /**
174:             * Logs the given message and Throwable at the 'fatal' level.
175:             * 
176:             * @param message
177:             *            the message to log
178:             * @param exception
179:             *            the throwable to log (may be null)
180:             */
181:            public void logFatal(Object message, Throwable exception) {
182:                logInternal(FATAL, message, exception);
183:            }
184:
185:            /**
186:             * Logs the given message instance using the 'info' level
187:             * 
188:             * @param message
189:             *            the message to log
190:             */
191:            public void logInfo(Object message) {
192:                logInternal(INFO, message, null);
193:            }
194:
195:            /**
196:             * Logs the given message and Throwable at the 'info' level.
197:             * 
198:             * @param message
199:             *            the message to log
200:             * @param exception
201:             *            the throwable to log (may be null)
202:             */
203:            public void logInfo(Object message, Throwable exception) {
204:                logInternal(INFO, message, exception);
205:            }
206:
207:            /**
208:             * Logs the given message instance using the 'trace' level
209:             * 
210:             * @param message
211:             *            the message to log
212:             */
213:            public void logTrace(Object message) {
214:                logInternal(TRACE, message, null);
215:            }
216:
217:            /**
218:             * Logs the given message and Throwable at the 'trace' level.
219:             * 
220:             * @param message
221:             *            the message to log
222:             * @param exception
223:             *            the throwable to log (may be null)
224:             */
225:            public void logTrace(Object message, Throwable exception) {
226:                logInternal(TRACE, message, exception);
227:            }
228:
229:            /**
230:             * Logs the given message instance using the 'warn' level
231:             * 
232:             * @param message
233:             *            the message to log
234:             */
235:            public void logWarn(Object message) {
236:                logInternal(WARN, message, null);
237:            }
238:
239:            /**
240:             * Logs the given message and Throwable at the 'warn' level.
241:             * 
242:             * @param message
243:             *            the message to log
244:             * @param exception
245:             *            the throwable to log (may be null)
246:             */
247:            public void logWarn(Object message, Throwable exception) {
248:                logInternal(WARN, message, exception);
249:            }
250:
251:            private void logInternal(int level, Object msg, Throwable exception) {
252:                StringBuffer msgBuf = new StringBuffer();
253:                msgBuf.append(new Date().toString());
254:                msgBuf.append(" ");
255:
256:                switch (level) {
257:                case FATAL:
258:                    msgBuf.append("FATAL: ");
259:
260:                    break;
261:
262:                case ERROR:
263:                    msgBuf.append("ERROR: ");
264:
265:                    break;
266:
267:                case WARN:
268:                    msgBuf.append("WARN: ");
269:
270:                    break;
271:
272:                case INFO:
273:                    msgBuf.append("INFO: ");
274:
275:                    break;
276:
277:                case DEBUG:
278:                    msgBuf.append("DEBUG: ");
279:
280:                    break;
281:
282:                case TRACE:
283:                    msgBuf.append("TRACE: ");
284:
285:                    break;
286:                }
287:
288:                if (msg instanceof  ProfilerEvent) {
289:                    msgBuf.append(LogUtils.expandProfilerEventIfNecessary(msg));
290:
291:                } else {
292:                    if (this .logLocationInfo && level != TRACE) {
293:                        Throwable locationException = new Throwable();
294:                        msgBuf.append(LogUtils
295:                                .findCallingClassAndMethod(locationException));
296:                        msgBuf.append(" ");
297:                    }
298:
299:                    if (msg != null) {
300:                        msgBuf.append(String.valueOf(msg));
301:                    }
302:                }
303:
304:                if (exception != null) {
305:                    msgBuf.append("\n");
306:                    msgBuf.append("\n");
307:                    msgBuf.append("EXCEPTION STACK TRACE:");
308:                    msgBuf.append("\n");
309:                    msgBuf.append("\n");
310:                    msgBuf.append(Util.stackTraceToString(exception));
311:                }
312:
313:                String messageAsString = msgBuf.toString();
314:
315:                System.err.println(messageAsString);
316:
317:                if (bufferedLog != null) {
318:                    bufferedLog.append(messageAsString);
319:                }
320:            }
321:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.