Source Code Cross Referenced for LogUtils.java in  » Web-Services-apache-cxf-2.0.1 » common » org » apache » cxf » common » 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 » Web Services apache cxf 2.0.1 » common » org.apache.cxf.common.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */package org.apache.cxf.common.logging;
019:
020:        import java.text.MessageFormat;
021:        import java.util.ResourceBundle;
022:        import java.util.logging.Level;
023:        import java.util.logging.LogRecord;
024:        import java.util.logging.Logger;
025:
026:        import org.apache.cxf.common.i18n.BundleUtils;
027:
028:        /**
029:         * A container for static utility methods related to logging.
030:         */
031:        public final class LogUtils {
032:
033:            private static final Object[] NO_PARAMETERS = new Object[0];
034:
035:            /**
036:             * Prevents instantiation.
037:             */
038:            private LogUtils() {
039:            }
040:
041:            /**
042:             * Get a Logger with the associated default resource bundle for the class.
043:             *
044:             * @param cls the Class to contain the Logger
045:             * @return an appropriate Logger 
046:             */
047:            public static Logger getL7dLogger(Class<?> cls) {
048:                return Logger.getLogger(cls.getName(), BundleUtils
049:                        .getBundleName(cls));
050:            }
051:
052:            /**
053:             * Get a Logger with an associated resource bundle.
054:             *
055:             * @param cls the Class to contain the Logger
056:             * @param name the resource name
057:             * @return an appropriate Logger 
058:             */
059:            public static Logger getL7dLogger(Class<?> cls, String name) {
060:                return Logger.getLogger(cls.getName(), BundleUtils
061:                        .getBundleName(cls, name));
062:            }
063:
064:            /**
065:             * Allows both parameter substitution and a typed Throwable to be logged.
066:             *
067:             * @param logger the Logger the log to
068:             * @param level the severity level
069:             * @param message the log message
070:             * @param throwable the Throwable to log
071:             * @param parameter the parameter to substitute into message
072:             */
073:            public static void log(Logger logger, Level level, String message,
074:                    Throwable throwable, Object parameter) {
075:                if (logger.isLoggable(level)) {
076:                    final String formattedMessage = MessageFormat.format(
077:                            localize(logger, message), parameter);
078:                    doLog(logger, level, formattedMessage, throwable);
079:                }
080:            }
081:
082:            /**
083:             * Allows both parameter substitution and a typed Throwable to be logged.
084:             *
085:             * @param logger the Logger the log to
086:             * @param level the severity level
087:             * @param message the log message
088:             * @param throwable the Throwable to log
089:             * @param parameters the parameters to substitute into message
090:             */
091:            public static void log(Logger logger, Level level, String message,
092:                    Throwable throwable, Object... parameters) {
093:                if (logger.isLoggable(level)) {
094:                    final String formattedMessage = MessageFormat.format(
095:                            localize(logger, message), parameters);
096:                    doLog(logger, level, formattedMessage, throwable);
097:                }
098:            }
099:
100:            /**
101:             * Checks log level and logs
102:             *
103:             * @param logger the Logger the log to
104:             * @param level the severity level
105:             * @param message the log message
106:             */
107:            public static void log(Logger logger, Level level, String message) {
108:                if (logger.isLoggable(level)) {
109:                    final String formattedMessage = MessageFormat.format(
110:                            localize(logger, message), NO_PARAMETERS);
111:                    doLog(logger, level, formattedMessage, null);
112:                }
113:
114:            }
115:
116:            /**
117:             * Checks log level and logs
118:             *
119:             * @param logger the Logger the log to
120:             * @param level the severity level
121:             * @param message the log message
122:             * @param throwable the Throwable to log
123:             */
124:            public static void log(Logger logger, Level level, String message,
125:                    Throwable throwable) {
126:                log(logger, level, message, throwable, NO_PARAMETERS);
127:            }
128:
129:            /**
130:             * Checks log level and logs
131:             *
132:             * @param logger the Logger the log to
133:             * @param level the severity level
134:             * @param message the log message
135:             * @param parameter the parameter to substitute into message
136:             */
137:            public static void log(Logger logger, Level level, String message,
138:                    Object parameter) {
139:                log(logger, level, message, new Object[] { parameter });
140:            }
141:
142:            /**
143:             * Checks log level and logs
144:             *
145:             * @param logger the Logger the log to
146:             * @param level the severity level
147:             * @param message the log message
148:             * @param parameters the parameters to substitute into message
149:             */
150:            public static void log(Logger logger, Level level, String message,
151:                    Object[] parameters) {
152:                if (logger.isLoggable(level)) {
153:                    final String formattedMessage = MessageFormat.format(
154:                            localize(logger, message), parameters);
155:                    doLog(logger, level, formattedMessage, null);
156:                }
157:
158:            }
159:
160:            private static void doLog(Logger log, Level level, String msg,
161:                    Throwable t) {
162:                LogRecord record = new LogRecord(level, msg);
163:
164:                record.setLoggerName(log.getName());
165:                record.setResourceBundleName(log.getResourceBundleName());
166:                record.setResourceBundle(log.getResourceBundle());
167:
168:                if (t != null) {
169:                    record.setThrown(t);
170:                }
171:
172:                //try to get the right class name/method name - just trace
173:                //back the stack till we get out of this class
174:                StackTraceElement stack[] = (new Throwable()).getStackTrace();
175:                String cname = LogUtils.class.getName();
176:                for (int x = 0; x < stack.length; x++) {
177:                    StackTraceElement frame = stack[x];
178:                    if (!frame.getClassName().equals(cname)) {
179:                        record.setSourceClassName(frame.getClassName());
180:                        record.setSourceMethodName(frame.getMethodName());
181:                        break;
182:                    }
183:                }
184:                log.log(record);
185:            }
186:
187:            /**
188:             * Retreive localized message retreived from a logger's resource
189:             * bundle.
190:             *
191:             * @param logger the Logger
192:             * @param message the message to be localized
193:             */
194:            private static String localize(Logger logger, String message) {
195:                ResourceBundle bundle = logger.getResourceBundle();
196:                return bundle != null ? bundle.getString(message) : message;
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.