Source Code Cross Referenced for SimpleLogger.java in  » Development » SLF4J » org » slf4j » impl » 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 » Development » SLF4J » org.slf4j.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2004-2005 SLF4J.ORG
003:         * Copyright (c) 2004-2005 QOS.ch
004:         *
005:         * All rights reserved.
006:         *
007:         * Permission is hereby granted, free of charge, to any person obtaining
008:         * a copy of this software and associated documentation files (the
009:         * "Software"), to  deal in  the Software without  restriction, including
010:         * without limitation  the rights to  use, copy, modify,  merge, publish,
011:         * distribute, and/or sell copies of  the Software, and to permit persons
012:         * to whom  the Software is furnished  to do so, provided  that the above
013:         * copyright notice(s) and this permission notice appear in all copies of
014:         * the  Software and  that both  the above  copyright notice(s)  and this
015:         * permission notice appear in supporting documentation.
016:         *
017:         * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
018:         * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
019:         * MERCHANTABILITY, FITNESS FOR  A PARTICULAR PURPOSE AND NONINFRINGEMENT
020:         * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
021:         * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
022:         * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
023:         * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
024:         * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
025:         * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
026:         *
027:         * Except as  contained in  this notice, the  name of a  copyright holder
028:         * shall not be used in advertising or otherwise to promote the sale, use
029:         * or other dealings in this Software without prior written authorization
030:         * of the copyright holder.
031:         *
032:         */
033:
034:        package org.slf4j.impl;
035:
036:        import org.slf4j.helpers.MarkerIgnoringBase;
037:        import org.slf4j.helpers.MessageFormatter;
038:
039:        /**
040:         * A simple (and direct) implementation that logs messages of level
041:         * INFO or higher on the console (<code>System.err<code>).
042:         *
043:         * <p>The output includes the relative time in milliseconds, thread
044:         * name, the level, logger name, and the message followed by the line
045:         * separator for the host.  In log4j terms it amounts to the "%r [%t]
046:         * %level %logger - %m%n" pattern. </p>
047:         *
048:         * <p>Sample output follows.</p>
049:         <pre>
050:         176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
051:         225 [main] INFO examples.SortAlgo - Entered the sort method.
052:         304 [main] INFO examples.SortAlgo - Dump of integer array:
053:         317 [main] INFO examples.SortAlgo - Element [0] = 0
054:         331 [main] INFO examples.SortAlgo - Element [1] = 1
055:         343 [main] INFO examples.Sort - The next log statement should be an error message.
056:         346 [main] ERROR examples.SortAlgo - Tried to dump an uninitialized array.
057:         at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
058:         at org.log4j.examples.Sort.main(Sort.java:64)
059:         467 [main] INFO  examples.Sort - Exiting main method.
060:         </pre>
061:         *
062:         * @author Ceki G&uuml;lc&uuml;
063:         */
064:        public class SimpleLogger extends MarkerIgnoringBase {
065:            /**
066:             * Mark the time when this class gets loaded into memory.
067:             */
068:            private static long startTime = System.currentTimeMillis();
069:            public static final String LINE_SEPARATOR = System
070:                    .getProperty("line.separator");
071:            private static String INFO_STR = "INFO";
072:            private static String WARN_STR = "WARN";
073:            private static String ERROR_STR = "ERROR";
074:            String name;
075:
076:            /**
077:             * Package access allows only {@link SimpleLoggerFactory} to instantiate
078:             * SimpleLogger instances.
079:             */
080:            SimpleLogger(String name) {
081:                this .name = name;
082:            }
083:
084:            public String getName() {
085:                return name;
086:            }
087:
088:            /**
089:             * Always returns false.
090:             * @return always false
091:             */
092:            public boolean isTraceEnabled() {
093:                return false;
094:            }
095:
096:            /**
097:             * A NOP implementation, as this logger is permanently disabled for
098:             * the TRACE level.
099:             */
100:            public void trace(String msg) {
101:                // NOP
102:            }
103:
104:            /**
105:             * A NOP implementation, as this logger is permanently disabled for
106:             * the TRACE level.
107:             */
108:            public void trace(String format, Object param1) {
109:                // NOP
110:            }
111:
112:            /**
113:             * A NOP implementation, as this logger is permanently disabled for
114:             * the TRACE level.
115:             */
116:            public void trace(String format, Object param1, Object param2) {
117:                // NOP
118:            }
119:
120:            public void trace(String format, Object[] argArray) {
121:                // NOP
122:            }
123:
124:            /**
125:             * A NOP implementation, as this logger is permanently disabled for
126:             * the TRACE level.
127:             */
128:            public void trace(String msg, Throwable t) {
129:                // NOP
130:            }
131:
132:            /**
133:             * Always returns false.
134:             * @return always false
135:             */
136:            public boolean isDebugEnabled() {
137:                return false;
138:            }
139:
140:            /**
141:             * A NOP implementation, as this logger is permanently disabled for
142:             * the DEBUG level.
143:             */
144:            public void debug(String msg) {
145:                // NOP
146:            }
147:
148:            /**
149:             * A NOP implementation, as this logger is permanently disabled for
150:             * the DEBUG level.
151:             */
152:            public void debug(String format, Object param1) {
153:                // NOP
154:            }
155:
156:            /**
157:             * A NOP implementation, as this logger is permanently disabled for
158:             * the DEBUG level.
159:             */
160:            public void debug(String format, Object param1, Object param2) {
161:                // NOP
162:            }
163:
164:            public void debug(String format, Object[] argArray) {
165:                // NOP
166:            }
167:
168:            /**
169:             * A NOP implementation, as this logger is permanently disabled for
170:             * the DEBUG level.
171:             */
172:            public void debug(String msg, Throwable t) {
173:                // NOP
174:            }
175:
176:            /**
177:             * This is our internal implementation for logging regular (non-parameterized)
178:             * log messages.
179:             *
180:             * @param level
181:             * @param message
182:             * @param t
183:             */
184:            private void log(String level, String message, Throwable t) {
185:                StringBuffer buf = new StringBuffer();
186:
187:                long millis = System.currentTimeMillis();
188:                buf.append(millis - startTime);
189:
190:                buf.append(" [");
191:                buf.append(Thread.currentThread().getName());
192:                buf.append("] ");
193:
194:                buf.append(level);
195:                buf.append(" ");
196:
197:                buf.append(name);
198:                buf.append(" - ");
199:
200:                buf.append(message);
201:
202:                buf.append(LINE_SEPARATOR);
203:
204:                System.err.print(buf.toString());
205:                if (t != null) {
206:                    t.printStackTrace(System.err);
207:                }
208:                System.err.flush();
209:            }
210:
211:            /**
212:             * For formatted messages, first substitute arguments and then log.
213:             *
214:             * @param level
215:             * @param format
216:             * @param param1
217:             * @param param2
218:             */
219:            private void formatAndLog(String level, String format, Object arg1,
220:                    Object arg2) {
221:                String message = MessageFormatter.format(format, arg1, arg2);
222:                log(level, message, null);
223:            }
224:
225:            /**
226:             * For formatted messages, first substitute arguments and then log.
227:             * 
228:             * @param level
229:             * @param format
230:             * @param argArray
231:             */
232:            private void formatAndLog(String level, String format,
233:                    Object[] argArray) {
234:                String message = MessageFormatter.arrayFormat(format, argArray);
235:                log(level, message, null);
236:            }
237:
238:            /**
239:             * Always returns true.
240:             */
241:            public boolean isInfoEnabled() {
242:                return true;
243:            }
244:
245:            /**
246:             * A simple implementation which always logs messages of level INFO according
247:             * to the format outlined above.
248:             */
249:            public void info(String msg) {
250:                log(INFO_STR, msg, null);
251:            }
252:
253:            /**
254:             * Perform single parameter substitution before logging the message of level
255:             * INFO according to the format outlined above.
256:             */
257:            public void info(String format, Object arg) {
258:                formatAndLog(INFO_STR, format, arg, null);
259:            }
260:
261:            /**
262:             * Perform double parameter substitution before logging the message of level
263:             * INFO according to the format outlined above.
264:             */
265:            public void info(String format, Object arg1, Object arg2) {
266:                formatAndLog(INFO_STR, format, arg1, arg2);
267:            }
268:
269:            /**
270:             * Perform double parameter substitution before logging the message of level
271:             * INFO according to the format outlined above.
272:             */
273:            public void info(String format, Object[] argArray) {
274:                formatAndLog(INFO_STR, format, argArray);
275:            }
276:
277:            /**
278:             * Log a message of level INFO, including an exception.
279:             */
280:            public void info(String msg, Throwable t) {
281:                log(INFO_STR, msg, t);
282:            }
283:
284:            /**
285:             * Always returns true.
286:             */
287:            public boolean isWarnEnabled() {
288:                return true;
289:            }
290:
291:            /**
292:             * A simple implementation which always logs messages of level WARN according
293:             * to the format outlined above.
294:             */
295:            public void warn(String msg) {
296:                log(WARN_STR, msg, null);
297:            }
298:
299:            /**
300:             * Perform single parameter substitution before logging the message of level
301:             * WARN according to the format outlined above.
302:             */
303:            public void warn(String format, Object arg) {
304:                formatAndLog(WARN_STR, format, arg, null);
305:            }
306:
307:            /**
308:             * Perform double parameter substitution before logging the message of level
309:             * WARN according to the format outlined above.
310:             */
311:            public void warn(String format, Object arg1, Object arg2) {
312:                formatAndLog(WARN_STR, format, arg1, arg2);
313:            }
314:
315:            /**
316:             * Perform double parameter substitution before logging the message of level
317:             * WARN according to the format outlined above.
318:             */
319:            public void warn(String format, Object[] argArray) {
320:                formatAndLog(WARN_STR, format, argArray);
321:            }
322:
323:            /**
324:             * Log a message of level WARN, including an exception.
325:             */
326:            public void warn(String msg, Throwable t) {
327:                log(WARN_STR, msg, t);
328:            }
329:
330:            /**
331:             * Always returns true.
332:             */
333:            public boolean isErrorEnabled() {
334:                return true;
335:            }
336:
337:            /**
338:             * A simple implementation which always logs messages of level ERROR according
339:             * to the format outlined above.
340:             */
341:            public void error(String msg) {
342:                log(ERROR_STR, msg, null);
343:            }
344:
345:            /**
346:             * Perform single parameter substitution before logging the message of level
347:             * ERROR according to the format outlined above.
348:             */
349:            public void error(String format, Object arg) {
350:                formatAndLog(ERROR_STR, format, arg, null);
351:            }
352:
353:            /**
354:             * Perform double parameter substitution before logging the message of level
355:             * ERROR according to the format outlined above.
356:             */
357:            public void error(String format, Object arg1, Object arg2) {
358:                formatAndLog(ERROR_STR, format, arg1, arg2);
359:            }
360:
361:            /**
362:             * Perform double parameter substitution before logging the message of level
363:             * ERROR according to the format outlined above.
364:             */
365:            public void error(String format, Object[] argArray) {
366:                formatAndLog(ERROR_STR, format, argArray);
367:            }
368:
369:            /**
370:             * Log a message of level ERROR, including an exception.
371:             */
372:            public void error(String msg, Throwable t) {
373:                log(ERROR_STR, msg, t);
374:            }
375:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.