Source Code Cross Referenced for LogFactory.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » juli » 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 » Sevlet Container » apache tomcat 6.0.14 » org.apache.juli.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.juli.logging;
019:
020:        import java.util.Properties;
021:
022:        /**
023:         * Modified LogFactory: removed all discovery, hardcode a specific implementation
024:         * If you like a different logging implementation - use either the discovery-based
025:         * commons-logging, or better - another implementation hardcoded to your favourite
026:         * logging impl.
027:         * 
028:         * Why ? Each application and deployment can choose a logging implementation - 
029:         * that involves configuration, installing the logger jar and optional plugins, etc.
030:         * As part of this process - they can as well install the commons-logging implementation
031:         * that corresponds to their logger of choice. This completely avoids any discovery
032:         * problem, while still allowing the user to switch. 
033:         * 
034:         * Note that this implementation is not just a wrapper arround JDK logging ( like
035:         * the original commons-logging impl ). It adds 2 features - a simpler configuration
036:         * ( which is in fact a subset of log4j.properties ) and a formatter that is 
037:         * less ugly.   
038:         * 
039:         * The removal of 'abstract' preserves binary backward compatibility. It is possible
040:         * to preserve the abstract - and introduce another ( hardcoded ) factory - but I 
041:         * see no benefit. 
042:         * 
043:         * Since this class is not intended to be extended - and provides
044:         * no plugin for other LogFactory implementation - all protected methods are removed.
045:         * This can be changed - but again, there is little value in keeping dead code.
046:         * Just take a quick look at the removed code ( and it's complexity)  
047:         * 
048:         * --------------
049:         * 
050:         * Original comment:
051:         * <p>Factory for creating {@link Log} instances, with discovery and
052:         * configuration features similar to that employed by standard Java APIs
053:         * such as JAXP.</p>
054:         * 
055:         * <p><strong>IMPLEMENTATION NOTE</strong> - This implementation is heavily
056:         * based on the SAXParserFactory and DocumentBuilderFactory implementations
057:         * (corresponding to the JAXP pluggability APIs) found in Apache Xerces.</p>
058:         * 
059:         *
060:         * @author Craig R. McClanahan
061:         * @author Costin Manolache
062:         * @author Richard A. Sitze
063:         * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
064:         */
065:        public/* abstract */class LogFactory {
066:
067:            // ----------------------------------------------------- Manifest Constants
068:
069:            /**
070:             * The name of the property used to identify the LogFactory implementation
071:             * class name.
072:             */
073:            public static final String FACTORY_PROPERTY = "org.apache.commons.logging.LogFactory";
074:
075:            /**
076:             * The fully qualified class name of the fallback <code>LogFactory</code>
077:             * implementation class to use, if no other can be found.
078:             */
079:            public static final String FACTORY_DEFAULT = "org.apache.commons.logging.impl.LogFactoryImpl";
080:
081:            /**
082:             * The name of the properties file to search for.
083:             */
084:            public static final String FACTORY_PROPERTIES = "commons-logging.properties";
085:
086:            /**
087:             * <p>Setting this system property value allows the <code>Hashtable</code> used to store
088:             * classloaders to be substituted by an alternative implementation.
089:             * </p>
090:             * <p>
091:             * <strong>Note:</strong> <code>LogFactory</code> will print:
092:             * <code><pre>
093:             * [ERROR] LogFactory: Load of custom hashtable failed</em>
094:             * </code></pre>
095:             * to system error and then continue using a standard Hashtable.
096:             * </p>
097:             * <p>
098:             * <strong>Usage:</strong> Set this property when Java is invoked
099:             * and <code>LogFactory</code> will attempt to load a new instance 
100:             * of the given implementation class.
101:             * For example, running the following ant scriplet:
102:             * <code><pre>
103:             *  &lt;java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}"&gt;
104:             *     ...
105:             *     &lt;sysproperty 
106:             *        key="org.apache.commons.logging.LogFactory.HashtableImpl"
107:             *        value="org.apache.commons.logging.AltHashtable"/&gt;
108:             *  &lt;/java&gt;
109:             * </pre></code>
110:             * will mean that <code>LogFactory</code> will load an instance of
111:             * <code>org.apache.commons.logging.AltHashtable</code>.
112:             * </p>
113:             * <p>
114:             * A typical use case is to allow a custom
115:             * Hashtable implementation using weak references to be substituted.
116:             * This will allow classloaders to be garbage collected without
117:             * the need to release them (on 1.3+ JVMs only, of course ;)
118:             * </p>
119:             */
120:            public static final String HASHTABLE_IMPLEMENTATION_PROPERTY = "org.apache.commons.logging.LogFactory.HashtableImpl";
121:
122:            private static LogFactory singleton = new LogFactory();
123:
124:            Properties logConfig;
125:
126:            // ----------------------------------------------------------- Constructors
127:
128:            /**
129:             * Protected constructor that is not available for public use.
130:             */
131:            private LogFactory() {
132:                logConfig = new Properties();
133:            }
134:
135:            // hook for syserr logger - class level
136:            void setLogConfig(Properties p) {
137:                this .logConfig = p;
138:            }
139:
140:            // --------------------------------------------------------- Public Methods
141:
142:            // only those 2 methods need to change to use a different direct logger.
143:
144:            /**
145:             * <p>Construct (if necessary) and return a <code>Log</code> instance,
146:             * using the factory's current set of configuration attributes.</p>
147:             *
148:             * <p><strong>NOTE</strong> - Depending upon the implementation of
149:             * the <code>LogFactory</code> you are using, the <code>Log</code>
150:             * instance you are returned may or may not be local to the current
151:             * application, and may or may not be returned again on a subsequent
152:             * call with the same name argument.</p>
153:             *
154:             * @param name Logical name of the <code>Log</code> instance to be
155:             *  returned (the meaning of this name is only known to the underlying
156:             *  logging implementation that is being wrapped)
157:             *
158:             * @exception LogConfigurationException if a suitable <code>Log</code>
159:             *  instance cannot be returned
160:             */
161:            public Log getInstance(String name)
162:                    throws LogConfigurationException {
163:                return DirectJDKLog.getInstance(name);
164:            }
165:
166:            /**
167:             * Release any internal references to previously created {@link Log}
168:             * instances returned by this factory.  This is useful in environments
169:             * like servlet containers, which implement application reloading by
170:             * throwing away a ClassLoader.  Dangling references to objects in that
171:             * class loader would prevent garbage collection.
172:             */
173:            public void release() {
174:                DirectJDKLog.release();
175:            }
176:
177:            /**
178:             * Return the configuration attribute with the specified name (if any),
179:             * or <code>null</code> if there is no such attribute.
180:             *
181:             * @param name Name of the attribute to return
182:             */
183:            public Object getAttribute(String name) {
184:                return logConfig.get(name);
185:            }
186:
187:            /**
188:             * Return an array containing the names of all currently defined
189:             * configuration attributes.  If there are no such attributes, a zero
190:             * length array is returned.
191:             */
192:            public String[] getAttributeNames() {
193:                return (String[]) logConfig.keySet().toArray();
194:            }
195:
196:            /**
197:             * Remove any configuration attribute associated with the specified name.
198:             * If there is no such attribute, no action is taken.
199:             *
200:             * @param name Name of the attribute to remove
201:             */
202:            public void removeAttribute(String name) {
203:                logConfig.remove(name);
204:            }
205:
206:            /**
207:             * Set the configuration attribute with the specified name.  Calling
208:             * this with a <code>null</code> value is equivalent to calling
209:             * <code>removeAttribute(name)</code>.
210:             *
211:             * @param name Name of the attribute to set
212:             * @param value Value of the attribute to set, or <code>null</code>
213:             *  to remove any setting for this attribute
214:             */
215:            public void setAttribute(String name, Object value) {
216:                logConfig.put(name, value);
217:            }
218:
219:            /**
220:             * Convenience method to derive a name from the specified class and
221:             * call <code>getInstance(String)</code> with it.
222:             *
223:             * @param clazz Class for which a suitable Log name will be derived
224:             *
225:             * @exception LogConfigurationException if a suitable <code>Log</code>
226:             *  instance cannot be returned
227:             */
228:            public Log getInstance(Class clazz)
229:                    throws LogConfigurationException {
230:                return getInstance(clazz.getName());
231:            }
232:
233:            // ------------------------------------------------------- Static Variables
234:
235:            // --------------------------------------------------------- Static Methods
236:
237:            /**
238:             * <p>Construct (if necessary) and return a <code>LogFactory</code>
239:             * instance, using the following ordered lookup procedure to determine
240:             * the name of the implementation class to be loaded.</p>
241:             * <ul>
242:             * <li>The <code>org.apache.commons.logging.LogFactory</code> system
243:             *     property.</li>
244:             * <li>The JDK 1.3 Service Discovery mechanism</li>
245:             * <li>Use the properties file <code>commons-logging.properties</code>
246:             *     file, if found in the class path of this class.  The configuration
247:             *     file is in standard <code>java.util.Properties</code> format and
248:             *     contains the fully qualified name of the implementation class
249:             *     with the key being the system property defined above.</li>
250:             * <li>Fall back to a default implementation class
251:             *     (<code>org.apache.commons.logging.impl.LogFactoryImpl</code>).</li>
252:             * </ul>
253:             *
254:             * <p><em>NOTE</em> - If the properties file method of identifying the
255:             * <code>LogFactory</code> implementation class is utilized, all of the
256:             * properties defined in this file will be set as configuration attributes
257:             * on the corresponding <code>LogFactory</code> instance.</p>
258:             *
259:             * @exception LogConfigurationException if the implementation class is not
260:             *  available or cannot be instantiated.
261:             */
262:            public static LogFactory getFactory()
263:                    throws LogConfigurationException {
264:                return singleton;
265:            }
266:
267:            /**
268:             * Convenience method to return a named logger, without the application
269:             * having to care about factories.
270:             *
271:             * @param clazz Class from which a log name will be derived
272:             *
273:             * @exception LogConfigurationException if a suitable <code>Log</code>
274:             *  instance cannot be returned
275:             */
276:            public static Log getLog(Class clazz)
277:                    throws LogConfigurationException {
278:                return (getFactory().getInstance(clazz));
279:
280:            }
281:
282:            /**
283:             * Convenience method to return a named logger, without the application
284:             * having to care about factories.
285:             *
286:             * @param name Logical name of the <code>Log</code> instance to be
287:             *  returned (the meaning of this name is only known to the underlying
288:             *  logging implementation that is being wrapped)
289:             *
290:             * @exception LogConfigurationException if a suitable <code>Log</code>
291:             *  instance cannot be returned
292:             */
293:            public static Log getLog(String name)
294:                    throws LogConfigurationException {
295:                return (getFactory().getInstance(name));
296:
297:            }
298:
299:            /**
300:             * Release any internal references to previously created {@link LogFactory}
301:             * instances that have been associated with the specified class loader
302:             * (if any), after calling the instance method <code>release()</code> on
303:             * each of them.
304:             *
305:             * @param classLoader ClassLoader for which to release the LogFactory
306:             */
307:            public static void release(ClassLoader classLoader) {
308:                // nothing - we don't use any class loaders
309:            }
310:
311:            /**
312:             * Release any internal references to previously created {@link LogFactory}
313:             * instances, after calling the instance method <code>release()</code> on
314:             * each of them.  This is useful in environments like servlet containers,
315:             * which implement application reloading by throwing away a ClassLoader.
316:             * Dangling references to objects in that class loader would prevent
317:             * garbage collection.
318:             */
319:            public static void releaseAll() {
320:                singleton.release();
321:            }
322:
323:            /**
324:             * Returns a string that uniquely identifies the specified object, including
325:             * its class.
326:             * <p>
327:             * The returned string is of form "classname@hashcode", ie is the same as
328:             * the return value of the Object.toString() method, but works even when
329:             * the specified object's class has overidden the toString method.
330:             * 
331:             * @param o may be null.
332:             * @return a string of form classname@hashcode, or "null" if param o is null.
333:             */
334:            public static String objectId(Object o) {
335:                if (o == null) {
336:                    return "null";
337:                } else {
338:                    return o.getClass().getName() + "@"
339:                            + System.identityHashCode(o);
340:                }
341:            }
342:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.