KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > util > configuration > TraceCarol


1 /**
2  * Copyright (C) 2002,2004 - INRIA (www.inria.fr)
3  *
4  * CAROL: Common Architecture for RMI ObjectWeb Layer
5  *
6  * This library is developed inside the ObjectWeb Consortium,
7  * http://www.objectweb.org
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22  * USA
23  *
24  * --------------------------------------------------------------------------
25  * $Id: TraceCarol.java,v 1.9 2005/03/15 17:54:52 benoitf Exp $
26  * --------------------------------------------------------------------------
27  */

28 package org.objectweb.carol.util.configuration;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 /**
34  * Class <code> TraceCarol </code> for Carol Trace configuration
35  */

36 public class TraceCarol {
37
38     /**
39      * prefix used to identify CAROL loggers
40      */

41     public static final String JavaDoc PREFIX = "org.objectweb.carol";
42
43     /**
44      * the carol logger jndiCarol and rmiCarol logger are children of carol
45      * logger
46      */

47     private static Log carolLogger = null;
48
49     /**
50      * Logger for PREFIX + ".jndi"
51      */

52     private static Log jndiCarolLogger = null;
53
54     /**
55      * Logger for PREFIX + ".jndi.enc"
56      */

57     private static Log jndiEncCarolLogger = null;
58
59     /**
60      * Logger for PREFIX + ".rmi"
61      */

62     private static Log rmiCarolLogger = null;
63
64     /**
65      * Logger for PREFIX + ".rmi.export"
66      */

67     private static Log exportCarolLogger = null;
68
69     /**
70      * Logger for PREFIX + ".cmi.des"
71      */

72     private static Log cmiDesLogger = null;
73
74     /**
75      * Logger for PREFIX + ".cmi.jndi"
76      */

77     private static Log cmiJndiLogger = null;
78
79     /**
80      * Logger for PREFIX + ".cmi.registry"
81      */

82     private static Log cmiRegistryLogger = null;
83
84
85     /**
86      * Utility class, no constructor
87      */

88     private TraceCarol() {
89
90     }
91
92     /**
93      * Configure the log for CAROL.
94      */

95     public static void configure() {
96         carolLogger = LogFactory.getLog(PREFIX);
97         jndiCarolLogger = LogFactory.getLog(PREFIX + ".jndi");
98         jndiEncCarolLogger = LogFactory.getLog(PREFIX + ".jndi.enc");
99         rmiCarolLogger = LogFactory.getLog(PREFIX + ".rmi");
100         exportCarolLogger = LogFactory.getLog(PREFIX + ".rmi.export");
101         cmiDesLogger = LogFactory.getLog(PREFIX + ".cmi.des");
102         cmiJndiLogger = LogFactory.getLog(PREFIX + ".cmi.jndi");
103         cmiRegistryLogger = LogFactory.getLog(PREFIX + ".cmi.registry");
104     }
105
106     /**
107      * Log a verbose message
108      * @param msg verbose message
109      */

110     public static void verbose(String JavaDoc msg) {
111         if (carolLogger != null) {
112             carolLogger.info(msg);
113         } else {
114             System.out.println("CAROL Verbose message:" + msg);
115         }
116     }
117
118     /**
119      * Log an error message.
120      * @param msg error message
121      */

122     public static void error(String JavaDoc msg) {
123         if (carolLogger != null) {
124             carolLogger.error(msg);
125         } else {
126             System.err.println("CAROL Error:" + msg);
127         }
128     }
129
130     /**
131      * Log an error message and a stack trace from a Throwable object.
132      * @param msg error message
133      * @param th Throwable object
134      */

135     public static void error(String JavaDoc msg, Throwable JavaDoc th) {
136         if (carolLogger != null) {
137             carolLogger.error(msg, th);
138         } else {
139             System.err.println("CAROL Error:" + msg);
140             th.printStackTrace();
141         }
142     }
143
144     /**
145      * Test if Carol debug messages are logged.
146      * @return boolean <code>true</code> if Carol debug messages are logged,
147      * <code>false</code> otherwise
148      */

149      public static boolean isDebugCarol() {
150         return (carolLogger != null) && carolLogger.isDebugEnabled();
151     }
152
153     /**
154      * Log a Carol debug message.
155      * @param msg CAROL debug message
156      */

157     public static void debugCarol(String JavaDoc msg) {
158         if (carolLogger != null) {
159             carolLogger.debug(msg);
160         }
161     }
162
163     /**
164      * Test if Carol info messages are logged.
165      * @return boolean <code>true</code> if Carol debug messages are logged,
166      * <code>false</code> otherwise
167      */

168      public static boolean isInfoCarol() {
169         return (carolLogger != null) && carolLogger.isInfoEnabled();
170     }
171
172     /**
173      * Log a Carol Info message.
174      * @param msg CAROL debug message
175      */

176     public static void infoCarol(String JavaDoc msg) {
177         if (carolLogger != null) {
178             carolLogger.info(msg);
179         }
180     }
181
182     /**
183      * Test if Jndi debug messages are logged.
184      * @return boolean <code>true</code> if Jndi debug messages are logged,
185      * <code>false</code> otherwise
186      */

187      public static boolean isDebugJndiCarol() {
188         return (jndiCarolLogger != null) && jndiCarolLogger.isDebugEnabled();
189     }
190
191     /**
192      * Log a Jndi debug message.
193      * @param msg Jndi debug message
194      */

195     public static void debugJndiCarol(String JavaDoc msg) {
196         if (jndiCarolLogger != null) {
197             jndiCarolLogger.debug(msg);
198         }
199     }
200
201     /**
202      * Test if Jndi ENC debug messages are logged.
203      * @return boolean <code>true</code> if Jndi debug messages are logged,
204      * <code>false</code> otherwise
205      */

206      public static boolean isDebugjndiEncCarol() {
207         return (jndiEncCarolLogger != null) && jndiEncCarolLogger.isDebugEnabled();
208     }
209
210     /**
211      * Log a Jndi ENC debug message.
212      * @param msg Jndi debug message
213      */

214     public static void debugjndiEncCarol(String JavaDoc msg) {
215         if (jndiEncCarolLogger != null) {
216             jndiEncCarolLogger.debug(msg);
217         }
218     }
219
220
221     /**
222      * Test if Rmi debug messages are logged.
223      * @return boolean <code>true</code> if Rmi debug messages are logged,
224      * <code>false</code> otherwise
225      */

226      public static boolean isDebugRmiCarol() {
227         return (rmiCarolLogger != null) && rmiCarolLogger.isDebugEnabled();
228     }
229
230     /**
231      * Log a Rmi debug message.
232      * @param msg Rmi debug message
233      */

234     public static void debugRmiCarol(String JavaDoc msg) {
235         if (rmiCarolLogger != null) {
236             rmiCarolLogger.debug(msg);
237         }
238     }
239
240     /**
241      * @return boolean true is is debug export
242      */

243     public static boolean isDebugExportCarol() {
244         return (exportCarolLogger != null) && exportCarolLogger.isDebugEnabled();
245     }
246
247     /**
248      * Debug export
249      * @param msg string
250      */

251     public static void debugExportCarol(String JavaDoc msg) {
252         if (exportCarolLogger != null) {
253             exportCarolLogger.debug(msg);
254         }
255     }
256
257     /**
258      * Test if Cmi DES debug messages are logged.
259      * @return boolean <code>true</code> if Cmi DES debug messages are logged,
260      * <code>false</code> otherwise
261      */

262      public static boolean isDebugCmiDes() {
263         return (cmiDesLogger != null) && cmiDesLogger.isDebugEnabled();
264     }
265
266     /**
267      * Log a Cmi DES debug message.
268      * @param msg Cmi DES debug message
269      */

270     public static void debugCmiDes(String JavaDoc msg) {
271         if (cmiDesLogger != null) {
272             cmiDesLogger.debug(msg);
273         }
274     }
275
276     /**
277      * Test if Cmi JNDI debug messages are logged.
278      * @return boolean <code>true</code> if Cmi JNDI debug messages are
279      * logged, <code>false</code> otherwise
280      */

281      public static boolean isDebugCmiJndi() {
282         return (cmiJndiLogger != null) && cmiJndiLogger.isDebugEnabled();
283     }
284
285     /**
286      * Log a Cmi JNDI debug message.
287      * @param msg Cmi JNDI debug message
288      */

289     public static void debugCmiJndi(String JavaDoc msg) {
290         if (cmiJndiLogger != null) {
291             cmiJndiLogger.debug(msg);
292         }
293     }
294
295     /**
296      * Test if Cmi registry debug messages are logged.
297      * @return boolean <code>true</code> if Cmi registry debug messages are
298      * logged, <code>false</code> otherwise
299      */

300      public static boolean isDebugCmiRegistry() {
301         return (cmiRegistryLogger != null) && cmiRegistryLogger.isDebugEnabled();
302     }
303
304     /**
305      * Log a Cmi registry debug message.
306      * @param msg Cmi registry debug message
307      */

308     public static void debugCmiRegistry(String JavaDoc msg) {
309         if (cmiRegistryLogger != null) {
310             cmiRegistryLogger.debug(msg);
311         }
312     }
313
314 }
Popular Tags