KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > plugins > LogUtils


1 /* $Id: LogUtils.java 155412 2005-02-26 12:58:36Z dirkv $
2  *
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.commons.digester.plugins;
18
19 import org.apache.commons.digester.Digester;
20 import org.apache.commons.logging.Log;
21
22 /**
23  * Simple utility class to assist in logging.
24  * <p>
25  * This class is intended only for the use of the code in the
26  * plugins packages. No "user" code should use this package.
27  * <p>
28  * The Digester module has an interesting approach to logging:
29  * all logging should be done via the Log object stored on the
30  * digester instance that the object *doing* the logging is associated
31  * with.
32  * <p>
33  * This is done because apparently some "container"-type applications
34  * such as Avalon and Tomcat need to be able to configure different logging
35  * for different <i>instances</i> of the Digester class which have been
36  * loaded from the same ClassLoader [info from Craig McClanahan].
37  * Not only the logging of the Digester instance should be affected; all
38  * objects associated with that Digester instance should obey the
39  * reconfiguration of their owning Digester instance's logging. The current
40  * solution is to force all objects to output logging info via a single
41  * Log object stored on the Digester instance they are associated with.
42  * <p>
43  * Of course this causes problems if logging is attempted before an
44  * object <i>has</i> a valid reference to its owning Digester. The
45  * getLogging method provided here resolves this issue by returning a
46  * Log object which silently discards all logging output in this
47  * situation.
48  * <p>
49  * And it also implies that logging filtering can no longer be applied
50  * to subcomponents of the Digester, because all logging is done via
51  * a single Log object (a single Category). C'est la vie...
52  *
53  * @since 1.6
54  */

55
56 class LogUtils {
57     
58   /**
59    * Get the Log object associated with the specified Digester instance,
60    * or a "no-op" logging object if the digester reference is null.
61    * <p>
62    * You should use this method instead of digester.getLogger() in
63    * any situation where the digester might be null.
64    */

65   static Log getLogger(Digester digester) {
66     if (digester == null) {
67         return new org.apache.commons.logging.impl.NoOpLog();
68     }
69     
70     return digester.getLogger();
71   }
72 }
73
Popular Tags