Source Code Cross Referenced for Log4jLoggerAdapter.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.apache.log4j.Level;
037:        import org.slf4j.Logger;
038:        import org.slf4j.Marker;
039:        import org.slf4j.helpers.MarkerIgnoringBase;
040:        import org.slf4j.helpers.MessageFormatter;
041:        import org.slf4j.spi.LocationAwareLogger;
042:
043:        /**
044:         * A wrapper over {@link org.apache.log4j.Logger
045:         * org.apache.log4j.Logger} in conformance with the {@link Logger}
046:         * interface. Note that the logging levels mentioned in this class
047:         * refer to those defined in the 
048:         * <a href="http://logging.apache.org/log4j/docs/api/org/apache/log4j/Level.html"><code>org.apache.log4j.Level</code></a>
049:         * class.
050:
051:         * @author Ceki G&uuml;lc&uuml;
052:         */
053:        public final class Log4jLoggerAdapter extends MarkerIgnoringBase
054:                implements  LocationAwareLogger {
055:            final org.apache.log4j.Logger logger;
056:
057:            /**
058:             * Following the pattern discussed in pages 162 through 168 of 
059:             * "The complete log4j manual".
060:             */
061:            final static String FQCN = Log4jLoggerAdapter.class.getName();
062:
063:            // WARN: Log4jLoggerAdapter constructor should have only package access so that
064:            // only Log4jLoggerFactory be able to create one.
065:            Log4jLoggerAdapter(org.apache.log4j.Logger logger) {
066:                this .logger = logger;
067:            }
068:
069:            public String getName() {
070:                return logger.getName();
071:            }
072:
073:            /**
074:             * Is this logger instance enabled for the TRACE level?
075:             *
076:             * @return True if this Logger is enabled for level TRACE, false
077:             * otherwise.
078:             */
079:            public boolean isTraceEnabled() {
080:                return logger.isTraceEnabled();
081:            }
082:
083:            /**
084:             * Log a message object at level TRACE.
085:             * @param msg - the message object to be logged
086:             */
087:            public void trace(String msg) {
088:                logger.log(FQCN, Level.TRACE, msg, null);
089:            }
090:
091:            /**
092:             * Log a message at level TRACE according to the specified format and
093:             * argument.
094:             *
095:             * <p>This form avoids superfluous object creation when the logger
096:             * is disabled for level TRACE. </p>
097:             *
098:             * @param format the format string
099:             * @param arg  the argument
100:             */
101:            public void trace(String format, Object arg) {
102:                if (logger.isTraceEnabled()) {
103:                    String msgStr = MessageFormatter.format(format, arg);
104:                    logger.log(FQCN, Level.TRACE, msgStr, null);
105:                }
106:            }
107:
108:            /**
109:             * Log a message at level TRACE according to the specified format and
110:             * arguments.
111:             *
112:             * <p>This form avoids superfluous object creation when the logger
113:             * is disabled for the TRACE level. </p>
114:             *
115:             * @param format the format string
116:             * @param arg1  the first argument
117:             * @param arg2  the second argument
118:             */
119:            public void trace(String format, Object arg1, Object arg2) {
120:                if (logger.isTraceEnabled()) {
121:                    String msgStr = MessageFormatter.format(format, arg1, arg2);
122:                    logger.log(FQCN, Level.TRACE, msgStr, null);
123:                }
124:            }
125:
126:            /**
127:             * Log a message at level TRACE according to the specified format and
128:             * arguments.
129:             *
130:             * <p>This form avoids superfluous object creation when the logger
131:             * is disabled for the TRACE level. </p>
132:             *
133:             * @param format the format string
134:             * @param argArray an array of arguments
135:             */
136:            public void trace(String format, Object[] argArray) {
137:                if (logger.isTraceEnabled()) {
138:                    String msgStr = MessageFormatter.arrayFormat(format,
139:                            argArray);
140:                    logger.log(FQCN, Level.TRACE, msgStr, null);
141:                }
142:            }
143:
144:            /**
145:             * Log an exception (throwable) at  level TRACE with an
146:             * accompanying message.
147:             *
148:             * @param msg the message accompanying the exception
149:             * @param t the exception (throwable) to log
150:             */
151:            public void trace(String msg, Throwable t) {
152:                logger.log(FQCN, Level.TRACE, msg, t);
153:            }
154:
155:            /**
156:             * Is this logger instance enabled for the DEBUG level?
157:             *
158:             * @return True if this Logger is enabled for level DEBUG, false
159:             * otherwise.
160:             */
161:            public boolean isDebugEnabled() {
162:                return logger.isDebugEnabled();
163:            }
164:
165:            /**
166:             * Log a message object at level DEBUG.
167:             * @param msg - the message object to be logged
168:             */
169:            public void debug(String msg) {
170:                logger.log(FQCN, Level.DEBUG, msg, null);
171:            }
172:
173:            /**
174:             * Log a message at level DEBUG according to the specified format and
175:             * argument.
176:             *
177:             * <p>This form avoids superfluous object creation when the logger
178:             * is disabled for level DEBUG. </p>
179:             *
180:             * @param format the format string
181:             * @param arg  the argument
182:             */
183:            public void debug(String format, Object arg) {
184:                if (logger.isDebugEnabled()) {
185:                    String msgStr = MessageFormatter.format(format, arg);
186:                    logger.log(FQCN, Level.DEBUG, msgStr, null);
187:                }
188:            }
189:
190:            /**
191:             * Log a message at level DEBUG according to the specified format and
192:             * arguments.
193:             *
194:             * <p>This form avoids superfluous object creation when the logger
195:             * is disabled for the DEBUG level. </p>
196:             *
197:             * @param format the format string
198:             * @param arg1  the first argument
199:             * @param arg2  the second argument
200:             */
201:            public void debug(String format, Object arg1, Object arg2) {
202:                if (logger.isDebugEnabled()) {
203:                    String msgStr = MessageFormatter.format(format, arg1, arg2);
204:                    logger.log(FQCN, Level.DEBUG, msgStr, null);
205:                }
206:            }
207:
208:            /**
209:             * Log a message at level DEBUG according to the specified format and
210:             * arguments.
211:             *
212:             * <p>This form avoids superfluous object creation when the logger
213:             * is disabled for the DEBUG level. </p>
214:             *
215:             * @param format the format string
216:             * @param argArray an array of arguments
217:             */
218:            public void debug(String format, Object[] argArray) {
219:                if (logger.isDebugEnabled()) {
220:                    String msgStr = MessageFormatter.arrayFormat(format,
221:                            argArray);
222:                    logger.log(FQCN, Level.DEBUG, msgStr, null);
223:                }
224:            }
225:
226:            /**
227:             * Log an exception (throwable) at  level DEBUG with an
228:             * accompanying message.
229:             *
230:             * @param msg the message accompanying the exception
231:             * @param t the exception (throwable) to log
232:             */
233:            public void debug(String msg, Throwable t) {
234:                logger.log(FQCN, Level.DEBUG, msg, t);
235:            }
236:
237:            /**
238:             * Is this logger instance enabled for the INFO level?
239:             *
240:             * @return True if this Logger is enabled for the INFO level, false
241:             * otherwise.
242:             */
243:            public boolean isInfoEnabled() {
244:                return logger.isInfoEnabled();
245:            }
246:
247:            /**
248:             * Log a message object at the INFO level.
249:             *
250:             * @param msg - the message object to be logged
251:             */
252:            public void info(String msg) {
253:                logger.log(FQCN, Level.INFO, msg, null);
254:            }
255:
256:            /**
257:             * Log a message at level INFO according to the specified format and
258:             * argument.
259:             *
260:             * <p>This form avoids superfluous object creation when the logger
261:             * is disabled for the INFO level. </p>
262:             *
263:             * @param format the format string
264:             * @param arg  the argument
265:             */
266:            public void info(String format, Object arg) {
267:                if (logger.isInfoEnabled()) {
268:                    String msgStr = MessageFormatter.format(format, arg);
269:                    logger.log(FQCN, Level.INFO, msgStr, null);
270:                }
271:            }
272:
273:            /**
274:             * Log a message at the INFO level according to the specified format
275:             * and arguments.
276:             *
277:             * <p>This form avoids superfluous object creation when the logger
278:             * is disabled for the INFO level. </p>
279:             *
280:             * @param format the format string
281:             * @param arg1  the first argument
282:             * @param arg2  the second argument
283:             */
284:            public void info(String format, Object arg1, Object arg2) {
285:                if (logger.isInfoEnabled()) {
286:                    String msgStr = MessageFormatter.format(format, arg1, arg2);
287:                    logger.log(FQCN, Level.INFO, msgStr, null);
288:                }
289:            }
290:
291:            /**
292:             * Log a message at level INFO according to the specified format and
293:             * arguments.
294:             *
295:             * <p>This form avoids superfluous object creation when the logger
296:             * is disabled for the INFO level. </p>
297:             *
298:             * @param format the format string
299:             * @param argArray an array of arguments
300:             */
301:            public void info(String format, Object[] argArray) {
302:                if (logger.isInfoEnabled()) {
303:                    String msgStr = MessageFormatter.arrayFormat(format,
304:                            argArray);
305:                    logger.log(FQCN, Level.INFO, msgStr, null);
306:                }
307:            }
308:
309:            /**
310:             * Log an exception (throwable) at the INFO level with an
311:             * accompanying message.
312:             *
313:             * @param msg the message accompanying the exception
314:             * @param t the exception (throwable) to log
315:             */
316:            public void info(String msg, Throwable t) {
317:                logger.log(FQCN, Level.INFO, msg, t);
318:            }
319:
320:            /**
321:             * Is this logger instance enabled for the WARN level?
322:             *
323:             * @return True if this Logger is enabled for the WARN level,
324:             * false otherwise.
325:             */
326:            public boolean isWarnEnabled() {
327:                return logger.isEnabledFor(Level.WARN);
328:            }
329:
330:            /**
331:             * Log a message object at the WARN level.
332:             *
333:             * @param msg - the message object to be logged
334:             */
335:            public void warn(String msg) {
336:                logger.log(FQCN, Level.WARN, msg, null);
337:            }
338:
339:            /**
340:             * Log a message at the WARN level according to the specified
341:             * format and argument.
342:             *
343:             * <p>This form avoids superfluous object creation when the logger
344:             * is disabled for the WARN level. </p>
345:             *
346:             * @param format the format string
347:             * @param arg  the argument
348:             */
349:            public void warn(String format, Object arg) {
350:                if (logger.isEnabledFor(Level.WARN)) {
351:                    String msgStr = MessageFormatter.format(format, arg);
352:                    logger.log(FQCN, Level.WARN, msgStr, null);
353:                }
354:            }
355:
356:            /**
357:             * Log a message at the WARN level according to the specified
358:             * format and arguments.
359:             *
360:             * <p>This form avoids superfluous object creation when the logger
361:             * is disabled for the WARN level. </p>
362:             *
363:             * @param format the format string
364:             * @param arg1  the first argument
365:             * @param arg2  the second argument
366:             */
367:            public void warn(String format, Object arg1, Object arg2) {
368:                if (logger.isEnabledFor(Level.WARN)) {
369:                    String msgStr = MessageFormatter.format(format, arg1, arg2);
370:                    logger.log(FQCN, Level.WARN, msgStr, null);
371:                }
372:            }
373:
374:            /**
375:             * Log a message at level WARN according to the specified format and
376:             * arguments.
377:             *
378:             * <p>This form avoids superfluous object creation when the logger
379:             * is disabled for the WARN level. </p>
380:             *
381:             * @param format the format string
382:             * @param argArray an array of arguments
383:             */
384:            public void warn(String format, Object[] argArray) {
385:                if (logger.isEnabledFor(Level.WARN)) {
386:                    String msgStr = MessageFormatter.arrayFormat(format,
387:                            argArray);
388:                    logger.log(FQCN, Level.WARN, msgStr, null);
389:                }
390:            }
391:
392:            /**
393:             * Log an exception (throwable) at the WARN level with an
394:             * accompanying message.
395:             *
396:             * @param msg the message accompanying the exception
397:             * @param t the exception (throwable) to log
398:             */
399:            public void warn(String msg, Throwable t) {
400:                logger.log(FQCN, Level.WARN, msg, t);
401:            }
402:
403:            /**
404:             * Is this logger instance enabled for level ERROR?
405:             *
406:             * @return True if this Logger is enabled for level ERROR, false
407:             * otherwise.
408:             */
409:            public boolean isErrorEnabled() {
410:                return logger.isEnabledFor(Level.ERROR);
411:            }
412:
413:            /**
414:             * Log a message object at the ERROR level.
415:             *
416:             * @param msg - the message object to be logged
417:             */
418:            public void error(String msg) {
419:                logger.log(FQCN, Level.ERROR, msg, null);
420:            }
421:
422:            /**
423:             * Log a message at the ERROR level according to the specified
424:             * format and argument.
425:             *
426:             * <p>This form avoids superfluous object creation when the logger
427:             * is disabled for the ERROR level. </p>
428:             *
429:             * @param format the format string
430:             * @param arg  the argument
431:             */
432:            public void error(String format, Object arg) {
433:                if (logger.isEnabledFor(Level.ERROR)) {
434:                    String msgStr = MessageFormatter.format(format, arg);
435:                    logger.log(FQCN, Level.ERROR, msgStr, null);
436:                }
437:            }
438:
439:            /**
440:             * Log a message at the ERROR level according to the specified
441:             * format and arguments.
442:             *
443:             * <p>This form avoids superfluous object creation when the logger
444:             * is disabled for the ERROR level. </p>
445:             *
446:             * @param format the format string
447:             * @param arg1  the first argument
448:             * @param arg2  the second argument
449:             */
450:            public void error(String format, Object arg1, Object arg2) {
451:                if (logger.isEnabledFor(Level.ERROR)) {
452:                    String msgStr = MessageFormatter.format(format, arg1, arg2);
453:                    logger.log(FQCN, Level.ERROR, msgStr, null);
454:                }
455:            }
456:
457:            /**
458:             * Log a message at level ERROR according to the specified format and
459:             * arguments.
460:             *
461:             * <p>This form avoids superfluous object creation when the logger
462:             * is disabled for the ERROR level. </p>
463:             *
464:             * @param format the format string
465:             * @param argArray an array of arguments
466:             */
467:            public void error(String format, Object[] argArray) {
468:                if (logger.isEnabledFor(Level.ERROR)) {
469:                    String msgStr = MessageFormatter.arrayFormat(format,
470:                            argArray);
471:                    logger.log(FQCN, Level.ERROR, msgStr, null);
472:                }
473:            }
474:
475:            /**
476:             * Log an exception (throwable) at the ERROR level with an
477:             * accompanying message.
478:             *
479:             * @param msg the message accompanying the exception
480:             * @param t the exception (throwable) to log
481:             */
482:            public void error(String msg, Throwable t) {
483:                logger.log(FQCN, Level.ERROR, msg, t);
484:            }
485:
486:            public void log(Marker marker, String callerFQCN, int level,
487:                    String msg, Throwable t) {
488:                Level log4jLevel;
489:                switch (level) {
490:                case LocationAwareLogger.TRACE_INT:
491:                    log4jLevel = Level.TRACE;
492:                    break;
493:                case LocationAwareLogger.DEBUG_INT:
494:                    log4jLevel = Level.DEBUG;
495:                    break;
496:                case LocationAwareLogger.INFO_INT:
497:                    log4jLevel = Level.INFO;
498:                    break;
499:                case LocationAwareLogger.WARN_INT:
500:                    log4jLevel = Level.WARN;
501:                    break;
502:                case LocationAwareLogger.ERROR_INT:
503:                    log4jLevel = Level.ERROR;
504:                    break;
505:                default:
506:                    throw new IllegalStateException("Level number " + level
507:                            + " is not recognized.");
508:                }
509:                logger.log(callerFQCN, log4jLevel, msg, t);
510:            }
511:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.