Source Code Cross Referenced for Log4jMLog.java in  » Database-JDBC-Connection-Pool » c3p0 » com » mchange » v2 » log » log4j » 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 » c3p0 » com.mchange.v2.log.log4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Distributed as part of c3p0 v.0.9.1.2
003:         *
004:         * Copyright (C) 2005 Machinery For Change, Inc.
005:         *
006:         * Author: Steve Waldman <swaldman@mchange.com>
007:         *
008:         * This library is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU Lesser General Public License version 2.1, as 
010:         * published by the Free Software Foundation.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public License
018:         * along with this software; see the file LICENSE.  If not, write to the
019:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         */
022:
023:        package com.mchange.v2.log.log4j;
024:
025:        import java.text.*;
026:        import java.util.*;
027:
028:        import com.mchange.v2.log.*;
029:        import com.mchange.v2.util.DoubleWeakHashMap;
030:
031:        import org.apache.log4j.*;
032:
033:        public final class Log4jMLog extends MLog {
034:            final static String CHECK_CLASS = "org.apache.log4j.Logger";
035:
036:            MLogger global = null;
037:
038:            public Log4jMLog() throws ClassNotFoundException {
039:                Class.forName(CHECK_CLASS);
040:            }
041:
042:            public MLogger getMLogger(String name) {
043:                Logger lg = Logger.getLogger(name);
044:                return new Log4jMLogger(lg);
045:            }
046:
047:            public MLogger getMLogger(Class cl) {
048:                Logger lg = Logger.getLogger(cl);
049:                return new Log4jMLogger(lg);
050:            }
051:
052:            public MLogger getMLogger() {
053:                Logger lg = Logger.getRootLogger();
054:                return new Log4jMLogger(lg);
055:            }
056:
057:            private final static class Log4jMLogger implements  MLogger {
058:                final static String FQCN = Log4jMLogger.class.getName();
059:
060:                // protected by this' lock
061:                MLevel myLevel = null;
062:
063:                volatile Logger logger;
064:
065:                Log4jMLogger(Logger logger) {
066:                    this .logger = logger;
067:                }
068:
069:                private static MLevel guessMLevel(Level lvl) {
070:                    if (lvl == null)
071:                        return null;
072:                    else if (lvl == Level.ALL)
073:                        return MLevel.ALL;
074:                    else if (lvl == Level.DEBUG)
075:                        return MLevel.FINEST;
076:                    else if (lvl == Level.ERROR)
077:                        return MLevel.SEVERE;
078:                    else if (lvl == Level.FATAL)
079:                        return MLevel.SEVERE;
080:                    else if (lvl == Level.INFO)
081:                        return MLevel.INFO;
082:                    else if (lvl == Level.OFF)
083:                        return MLevel.OFF;
084:                    else if (lvl == Level.WARN)
085:                        return MLevel.WARNING;
086:                    else
087:                        throw new IllegalArgumentException("Unknown level: "
088:                                + lvl);
089:                }
090:
091:                private static Level level(MLevel lvl) {
092:                    if (lvl == null)
093:                        return null;
094:                    else if (lvl == MLevel.ALL)
095:                        return Level.ALL;
096:                    else if (lvl == MLevel.CONFIG)
097:                        return Level.DEBUG;
098:                    else if (lvl == MLevel.FINE)
099:                        return Level.DEBUG;
100:                    else if (lvl == MLevel.FINER)
101:                        return Level.DEBUG;
102:                    else if (lvl == MLevel.FINEST)
103:                        return Level.DEBUG;
104:                    else if (lvl == MLevel.INFO)
105:                        return Level.INFO;
106:                    else if (lvl == MLevel.INFO)
107:                        return Level.OFF;
108:                    else if (lvl == MLevel.SEVERE)
109:                        return Level.ERROR;
110:                    else if (lvl == MLevel.WARNING)
111:                        return Level.WARN;
112:                    else
113:                        throw new IllegalArgumentException("Unknown MLevel: "
114:                                + lvl);
115:                }
116:
117:                private static String createMessage(String srcClass,
118:                        String srcMeth, String msg) {
119:                    StringBuffer sb = new StringBuffer(511);
120:                    sb.append("[class: ");
121:                    sb.append(srcClass);
122:                    sb.append("; method: ");
123:                    sb.append(srcMeth);
124:                    if (!srcMeth.endsWith(")"))
125:                        sb.append("()");
126:                    sb.append("] ");
127:                    sb.append(msg);
128:                    return sb.toString();
129:                }
130:
131:                private static String createMessage(String srcMeth, String msg) {
132:                    StringBuffer sb = new StringBuffer(511);
133:                    sb.append("[method: ");
134:                    sb.append(srcMeth);
135:                    if (!srcMeth.endsWith(")"))
136:                        sb.append("()");
137:                    sb.append("] ");
138:                    sb.append(msg);
139:                    return sb.toString();
140:                }
141:
142:                public ResourceBundle getResourceBundle() {
143:                    return null;
144:                }
145:
146:                public String getResourceBundleName() {
147:                    return null;
148:                }
149:
150:                public void setFilter(Object java14Filter)
151:                        throws SecurityException {
152:                    warning("setFilter() not supported by MLogger "
153:                            + this .getClass().getName());
154:                }
155:
156:                public Object getFilter() {
157:                    return null;
158:                }
159:
160:                private void log(Level lvl, Object msg, Throwable t) {
161:                    logger.log(FQCN, lvl, msg, t);
162:                }
163:
164:                public void log(MLevel l, String msg) {
165:                    log(level(l), msg, null);
166:                }
167:
168:                public void log(MLevel l, String msg, Object param) {
169:                    log(level(l), (msg != null ? MessageFormat.format(msg,
170:                            new Object[] { param }) : null), null);
171:                }
172:
173:                public void log(MLevel l, String msg, Object[] params) {
174:                    log(level(l), (msg != null ? MessageFormat.format(msg,
175:                            params) : null), null);
176:                }
177:
178:                public void log(MLevel l, String msg, Throwable t) {
179:                    log(level(l), msg, t);
180:                }
181:
182:                public void logp(MLevel l, String srcClass, String srcMeth,
183:                        String msg) {
184:                    log(level(l), createMessage(srcClass, srcMeth, msg), null);
185:                }
186:
187:                public void logp(MLevel l, String srcClass, String srcMeth,
188:                        String msg, Object param) {
189:                    log(level(l), createMessage(srcClass, srcMeth,
190:                            (msg != null ? MessageFormat.format(msg,
191:                                    new Object[] { param }) : null)), null);
192:                }
193:
194:                public void logp(MLevel l, String srcClass, String srcMeth,
195:                        String msg, Object[] params) {
196:                    log(level(l), createMessage(srcClass, srcMeth,
197:                            (msg != null ? MessageFormat.format(msg, params)
198:                                    : null)), null);
199:                }
200:
201:                public void logp(MLevel l, String srcClass, String srcMeth,
202:                        String msg, Throwable t) {
203:                    log(level(l), createMessage(srcClass, srcMeth, msg), t);
204:                }
205:
206:                public void logrb(MLevel l, String srcClass, String srcMeth,
207:                        String rb, String msg) {
208:                    log(level(l), createMessage(srcClass, srcMeth,
209:                            formatMessage(rb, msg, null)), null);
210:                }
211:
212:                public void logrb(MLevel l, String srcClass, String srcMeth,
213:                        String rb, String msg, Object param) {
214:                    log(level(l), createMessage(srcClass, srcMeth,
215:                            formatMessage(rb, msg, new Object[] { param })),
216:                            null);
217:                }
218:
219:                public void logrb(MLevel l, String srcClass, String srcMeth,
220:                        String rb, String msg, Object[] params) {
221:                    log(level(l), createMessage(srcClass, srcMeth,
222:                            formatMessage(rb, msg, params)), null);
223:                }
224:
225:                public void logrb(MLevel l, String srcClass, String srcMeth,
226:                        String rb, String msg, Throwable t) {
227:                    log(level(l), createMessage(srcClass, srcMeth,
228:                            formatMessage(rb, msg, null)), t);
229:                }
230:
231:                public void entering(String srcClass, String srcMeth) {
232:                    log(Level.DEBUG, createMessage(srcClass, srcMeth,
233:                            "entering method."), null);
234:                }
235:
236:                public void entering(String srcClass, String srcMeth,
237:                        Object param) {
238:                    log(Level.DEBUG, createMessage(srcClass, srcMeth,
239:                            "entering method... param: " + param.toString()),
240:                            null);
241:                }
242:
243:                public void entering(String srcClass, String srcMeth,
244:                        Object params[]) {
245:                    log(Level.DEBUG, createMessage(srcClass, srcMeth,
246:                            "entering method... "
247:                                    + LogUtils.createParamsList(params)), null);
248:                }
249:
250:                public void exiting(String srcClass, String srcMeth) {
251:                    log(Level.DEBUG, createMessage(srcClass, srcMeth,
252:                            "exiting method."), null);
253:                }
254:
255:                public void exiting(String srcClass, String srcMeth,
256:                        Object result) {
257:                    log(Level.DEBUG, createMessage(srcClass, srcMeth,
258:                            "exiting method... result: " + result.toString()),
259:                            null);
260:                }
261:
262:                public void throwing(String srcClass, String srcMeth,
263:                        Throwable t) {
264:                    log(Level.DEBUG, createMessage(srcClass, srcMeth,
265:                            "throwing exception... "), t);
266:                }
267:
268:                public void severe(String msg) {
269:                    log(Level.ERROR, msg, null);
270:                }
271:
272:                public void warning(String msg) {
273:                    log(Level.WARN, msg, null);
274:                }
275:
276:                public void info(String msg) {
277:                    log(Level.INFO, msg, null);
278:                }
279:
280:                public void config(String msg) {
281:                    log(Level.DEBUG, msg, null);
282:                }
283:
284:                public void fine(String msg) {
285:                    log(Level.DEBUG, msg, null);
286:                }
287:
288:                public void finer(String msg) {
289:                    log(Level.DEBUG, msg, null);
290:                }
291:
292:                public void finest(String msg) {
293:                    log(Level.DEBUG, msg, null);
294:                }
295:
296:                public synchronized void setLevel(MLevel l)
297:                        throws SecurityException {
298:                    logger.setLevel(level(l));
299:                    myLevel = l;
300:                }
301:
302:                public synchronized MLevel getLevel() {
303:                    //System.err.println( logger.getLevel() );
304:                    if (myLevel == null)
305:                        myLevel = guessMLevel(logger.getLevel());
306:                    return myLevel;
307:                }
308:
309:                public boolean isLoggable(MLevel l) {
310:                    //System.err.println( "MLevel: " + l + "; isEnabledFor(): " + logger.isEnabledFor( level(l) ) + "; getLevel(): " + getLevel() +
311:                    //"; MLog.getLogger().getLevel(): " + MLog.getLogger().getLevel());
312:                    //new Exception("WHADDAFUC").printStackTrace();
313:                    return logger.isEnabledFor(level(l));
314:                }
315:
316:                public String getName() {
317:                    return logger.getName();
318:                }
319:
320:                public void addHandler(Object h) throws SecurityException {
321:                    if (!(h instanceof  Appender))
322:                        throw new IllegalArgumentException("The 'handler' " + h
323:                                + " is not compatible with MLogger " + this );
324:                    logger.addAppender((Appender) h);
325:                }
326:
327:                public void removeHandler(Object h) throws SecurityException {
328:                    if (!(h instanceof  Appender))
329:                        throw new IllegalArgumentException("The 'handler' " + h
330:                                + " is not compatible with MLogger " + this );
331:                    logger.removeAppender((Appender) h);
332:                }
333:
334:                public Object[] getHandlers() {
335:                    List tmp = new LinkedList();
336:                    for (Enumeration e = logger.getAllAppenders(); e
337:                            .hasMoreElements();)
338:                        tmp.add(e.nextElement());
339:                    return tmp.toArray();
340:                }
341:
342:                public void setUseParentHandlers(boolean uph) {
343:                    logger.setAdditivity(uph);
344:                }
345:
346:                public boolean getUseParentHandlers() {
347:                    return logger.getAdditivity();
348:                }
349:            }
350:
351:            private static String formatMessage(String rbname, String msg,
352:                    Object[] params) {
353:                if (msg == null) {
354:                    if (params == null)
355:                        return "";
356:                    else
357:                        return LogUtils.createParamsList(params);
358:                } else {
359:                    ResourceBundle rb = ResourceBundle.getBundle(rbname);
360:                    if (rb != null) {
361:                        String check = rb.getString(msg);
362:                        if (check != null)
363:                            msg = check;
364:                    }
365:                    return (params == null ? msg : MessageFormat.format(msg,
366:                            params));
367:                }
368:            }
369:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.