KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > jsfext > util > LogUtil


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.jsfext.util;
24
25 import com.sun.web.ui.util.MessageUtil;
26
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29
30
31 /**
32  * <p> This class provides helper methods for logging messages. It uses
33  * standard J2SE logging. However, using these API's is abstracts this
34  * away from our code in case we want to go back to Apache commons
35  * logging or some other logging API in the future.</p>
36  *
37  * <p> The logging levels follow the J2SE log level names, they are as
38  * follows:</p>
39  *
40  * <ul><li>FINEST -- Highly detailed tracing message</li>
41  * <li>FINER -- Fairly detailed tracing message</li>
42  * <li>FINE -- Coarse tracing message</li>
43  * <li>CONFIG -- Static configuration messages</li>
44  * <li>INFO -- Informational messages (logged by default)</li>
45  * <li>WARNING -- Potentially problematic messages</li>
46  * <li>SEVERE -- Serious failure messages</li>
47  * </ul>
48  *
49  * @author Ken Paulsen (ken.paulsen@sun.com)
50  */

51 public class LogUtil {
52     // FIXME: Check w/ Hemanth to get an "approved" message ID prefix
53

54     ////////////////////////////////////////////////////////////
55
// FINEST LOGGING METHODS
56
////////////////////////////////////////////////////////////
57

58     /**
59      * <p> Method to check if this log level is enabled for the default
60      * logger.</p>
61      *
62      * @return true if the log level is enabled, false otherwise.
63      */

64     public static boolean finestEnabled() {
65     return getLogger().isLoggable(Level.FINEST);
66     }
67
68     /**
69      * <p> Method to check if this log level is enabled for the given
70      * logger.</p>
71      *
72      * @param loggerId The logger to check. This may be specified as a
73      * String or Class Object.
74      *
75      * @return true if the log level is enabled, false otherwise.
76      */

77     public static boolean finestEnabled(Object JavaDoc loggerId) {
78     return getLogger(loggerId).isLoggable(Level.FINEST);
79     }
80
81     /**
82      * <p> Logging method supporting a localized message key and a single
83      * substitution parameter. It will use the default Logger.</p>
84      *
85      * @param msgId The <code>ResourceBundle</code> key used to lookup
86      * the message.
87      *
88      * @param param Value to substitute into the message.
89      *
90      * @see LogUtil#BUNDLE_NAME
91      */

92     public static void finest(String JavaDoc msgId, Object JavaDoc param) {
93     finest(msgId, new Object JavaDoc[] {param});
94     }
95
96     /**
97      * <p> Logging method supporting a localized message key and zero or more
98      * substitution parameters. It will use the default Logger.</p>
99      *
100      * @param msgId The <code>ResourceBundle</code> key used to lookup
101      * the message.
102      *
103      * @param params Value(s) to substitute into the message.
104      *
105      * @see LogUtil#BUNDLE_NAME
106      */

107     public static void finest(String JavaDoc msgId, Object JavaDoc[] params) {
108     getLogger().log(Level.FINEST, getMessage(msgId, params, false));
109     }
110
111     /**
112      * <p> Logging method supporting a localized message key, a single
113      * substitution parameter, and the ability to specify the Logger.</p>
114      *
115      * @param loggerId The logger to use. This may be specified as a
116      * String or Class Object.
117      *
118      * @param msgId The <code>ResourceBundle</code> key used to lookup
119      * the message.
120      *
121      * @param param Value to substitute into the message.
122      *
123      * @see LogUtil#BUNDLE_NAME
124      */

125     public static void finest(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc param) {
126     finest(loggerId, msgId, new Object JavaDoc[] {param});
127     }
128
129     /**
130      * <p> Logging method supporting a localized message key, zero or more
131      * substitution parameters, and the ability to specify the Logger.</p>
132      *
133      * @param loggerId The logger to use. This may be specified as a
134      * String or Class Object.
135      *
136      * @param msgId The <code>ResourceBundle</code> key used to lookup
137      * the message.
138      *
139      * @param params Value(s) to substitute into the message.
140      *
141      * @see LogUtil#BUNDLE_NAME
142      */

143     public static void finest(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc[] params) {
144     getLogger(loggerId).log(Level.FINEST, getMessage(msgId, params, false));
145     }
146
147     /**
148      * <p> Logging method to log a simple localized or non-localized message.
149      * This method will first attempt to find <code>msg</code> in the
150      * properties file, if not found it will print the given msg.</p>
151      *
152      * @param msg The message (or <code>ResourceBundle</code> key).
153      */

154     public static void finest(String JavaDoc msg) {
155     finest(DEFAULT_LOGGER, msg);
156     }
157
158     /**
159      * <p> Logging method to log a simple localized or non-localized message.
160      * This method will first attempt to find <code>msg</code> in the
161      * properties file, if not found it will print the given msg. The
162      * specified Logger will be used.</p>
163      *
164      * @param loggerId The logger to use. This may be specified as a
165      * String or Class Object.
166      *
167      * @param msg The message (or <code>ResourceBundle</code> key).
168      */

169     public static void finest(Object JavaDoc loggerId, String JavaDoc msg) {
170     getLogger(loggerId).log(Level.FINEST, getMessage(msg, false));
171     }
172
173     /**
174      * <p> Logging method to log a <code>Throwable</code> with a
175      * message.</p>
176      *
177      * @param msg The message.
178      *
179      * @param ex The <code>Throwable</code> to log.
180      */

181     public static void finest(String JavaDoc msg, Throwable JavaDoc ex) {
182     getLogger().log(Level.FINEST,
183         DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msg, ex);
184     }
185
186     /**
187      * <p> Logging method to log a <code>Throwable</code> with a
188      * message. The specified Logger will be used.</p>
189      *
190      * @param loggerId The logger to use. This may be specified as a
191      * String or Class Object.
192      *
193      * @param msg The message.
194      *
195      * @param ex The <code>Throwable</code> to log.
196      */

197     public static void finest(Object JavaDoc loggerId, String JavaDoc msg, Throwable JavaDoc ex) {
198     getLogger(loggerId).log(Level.FINEST,
199         DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msg, ex);
200     }
201
202
203     ////////////////////////////////////////////////////////////
204
// FINER LOGGING METHODS
205
////////////////////////////////////////////////////////////
206

207     /**
208      * <p> Method to check if this log level is enabled for the default
209      * logger.</p>
210      *
211      * @return true if the log level is enabled, false otherwise.
212      */

213     public static boolean finerEnabled() {
214     return getLogger().isLoggable(Level.FINER);
215     }
216
217     /**
218      * <p> Method to check if this log level is enabled for the given
219      * logger.</p>
220      *
221      * @param loggerId The logger to check. This may be specified as a
222      * String or Class Object.
223      *
224      * @return true if the log level is enabled, false otherwise.
225      */

226     public static boolean finerEnabled(Object JavaDoc loggerId) {
227     return getLogger(loggerId).isLoggable(Level.FINER);
228     }
229
230     /**
231      * <p> Logging method supporting a localized message key and a single
232      * substitution parameter. It will use the default Logger.</p>
233      *
234      * @param msgId The <code>ResourceBundle</code> key used to lookup
235      * the message.
236      *
237      * @param param Value to substitute into the message.
238      *
239      * @see LogUtil#BUNDLE_NAME
240      */

241     public static void finer(String JavaDoc msgId, Object JavaDoc param) {
242     finer(msgId, new Object JavaDoc[] {param});
243     }
244
245     /**
246      * <p> Logging method supporting a localized message key and zero or more
247      * substitution parameters. It will use the default Logger.</p>
248      *
249      * @param msgId The <code>ResourceBundle</code> key used to lookup
250      * the message.
251      *
252      * @param params Value(s) to substitute into the message.
253      *
254      * @see LogUtil#BUNDLE_NAME
255      */

256     public static void finer(String JavaDoc msgId, Object JavaDoc[] params) {
257     getLogger().log(Level.FINER, getMessage(msgId, params, false));
258     }
259
260     /**
261      * <p> Logging method supporting a localized message key, a single
262      * substitution parameter, and the ability to specify the Logger.</p>
263      *
264      * @param loggerId The logger to use. This may be specified as a
265      * String or Class Object.
266      *
267      * @param msgId The <code>ResourceBundle</code> key used to lookup
268      * the message.
269      *
270      * @param param Value to substitute into the message.
271      *
272      * @see LogUtil#BUNDLE_NAME
273      */

274     public static void finer(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc param) {
275     finer(loggerId, msgId, new Object JavaDoc[] {param});
276     }
277
278     /**
279      * <p> Logging method supporting a localized message key, zero or more
280      * substitution parameters, and the ability to specify the Logger.</p>
281      *
282      * @param loggerId The logger to use. This may be specified as a
283      * String or Class Object.
284      *
285      * @param msgId The <code>ResourceBundle</code> key used to lookup
286      * the message.
287      *
288      * @param params Value(s) to substitute into the message.
289      *
290      * @see LogUtil#BUNDLE_NAME
291      */

292     public static void finer(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc[] params) {
293     getLogger(loggerId).log(Level.FINER, getMessage(msgId, params, false));
294     }
295
296     /**
297      * <p> Logging method to log a simple localized or non-localized message.
298      * This method will first attempt to find <code>msg</code> in the
299      * properties file, if not found it will print the given msg.</p>
300      *
301      * @param msg The message (or <code>ResourceBundle</code> key).
302      */

303     public static void finer(String JavaDoc msg) {
304     finer(DEFAULT_LOGGER, msg);
305     }
306
307     /**
308      * <p> Logging method to log a simple localized or non-localized message.
309      * This method will first attempt to find <code>msg</code> in the
310      * properties file, if not found it will print the given msg. The
311      * specified Logger will be used.</p>
312      *
313      * @param loggerId The logger to use. This may be specified as a
314      * String or Class Object.
315      *
316      * @param msg The message (or <code>ResourceBundle</code> key).
317      */

318     public static void finer(Object JavaDoc loggerId, String JavaDoc msg) {
319     getLogger(loggerId).log(Level.FINER, getMessage(msg, false));
320     }
321
322     /**
323      * <p> Logging method to log a <code>Throwable</code> with a
324      * message.</p>
325      *
326      * @param msg The message.
327      *
328      * @param ex The <code>Throwable</code> to log.
329      */

330     public static void finer(String JavaDoc msg, Throwable JavaDoc ex) {
331     getLogger().log(Level.FINER,
332         DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msg, ex);
333     }
334
335     /**
336      * <p> Logging method to log a <code>Throwable</code> with a
337      * message. The specified Logger will be used.</p>
338      *
339      * @param loggerId The logger to use. This may be specified as a
340      * String or Class Object.
341      *
342      * @param msg The message.
343      *
344      * @param ex The <code>Throwable</code> to log.
345      */

346     public static void finer(Object JavaDoc loggerId, String JavaDoc msg, Throwable JavaDoc ex) {
347     getLogger(loggerId).log(Level.FINER,
348         DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msg, ex);
349     }
350
351
352     ////////////////////////////////////////////////////////////
353
// FINE LOGGING METHODS
354
////////////////////////////////////////////////////////////
355

356     /**
357      * <p> Method to check if this log level is enabled for the default
358      * logger.</p>
359      *
360      * @return true if the log level is enabled, false otherwise.
361      */

362     public static boolean fineEnabled() {
363     return getLogger().isLoggable(Level.FINE);
364     }
365
366     /**
367      * <p> Method to check if this log level is enabled for the given
368      * logger.</p>
369      *
370      * @param loggerId The logger to check. This may be specified as a
371      * String or Class Object.
372      *
373      * @return true if the log level is enabled, false otherwise.
374      */

375     public static boolean fineEnabled(Object JavaDoc loggerId) {
376     return getLogger(loggerId).isLoggable(Level.FINE);
377     }
378
379     /**
380      * <p> Logging method supporting a localized message key and a single
381      * substitution parameter. It will use the default Logger.</p>
382      *
383      * @param msgId The <code>ResourceBundle</code> key used to lookup
384      * the message.
385      *
386      * @param param Value to substitute into the message.
387      *
388      * @see LogUtil#BUNDLE_NAME
389      */

390     public static void fine(String JavaDoc msgId, Object JavaDoc param) {
391     fine(msgId, new Object JavaDoc[] {param});
392     }
393
394     /**
395      * <p> Logging method supporting a localized message key and zero or more
396      * substitution parameters. It will use the default Logger.</p>
397      *
398      * @param msgId The <code>ResourceBundle</code> key used to lookup
399      * the message.
400      *
401      * @param params Value(s) to substitute into the message.
402      *
403      * @see LogUtil#BUNDLE_NAME
404      */

405     public static void fine(String JavaDoc msgId, Object JavaDoc[] params) {
406     getLogger().log(Level.FINE, getMessage(msgId, params, false));
407     }
408
409     /**
410      * <p> Logging method supporting a localized message key, a single
411      * substitution parameter, and the ability to specify the Logger.</p>
412      *
413      * @param loggerId The logger to use. This may be specified as a
414      * String or Class Object.
415      *
416      * @param msgId The <code>ResourceBundle</code> key used to lookup
417      * the message.
418      *
419      * @param param Value to substitute into the message.
420      *
421      * @see LogUtil#BUNDLE_NAME
422      */

423     public static void fine(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc param) {
424     fine(loggerId, msgId, new Object JavaDoc[] {param});
425     }
426
427     /**
428      * <p> Logging method supporting a localized message key, zero or more
429      * substitution parameters, and the ability to specify the Logger.</p>
430      *
431      * @param loggerId The logger to use. This may be specified as a
432      * String or Class Object.
433      *
434      * @param msgId The <code>ResourceBundle</code> key used to lookup
435      * the message.
436      *
437      * @param params Value(s) to substitute into the message.
438      *
439      * @see LogUtil#BUNDLE_NAME
440      */

441     public static void fine(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc[] params) {
442     getLogger(loggerId).log(Level.FINE, getMessage(msgId, params, false));
443     }
444
445     /**
446      * <p> Logging method to log a simple localized or non-localized message.
447      * This method will first attempt to find <code>msg</code> in the
448      * properties file, if not found it will print the given msg.</p>
449      *
450      * @param msg The message (or <code>ResourceBundle</code> key).
451      */

452     public static void fine(String JavaDoc msg) {
453     fine(DEFAULT_LOGGER, msg);
454     }
455
456     /**
457      * <p> Logging method to log a simple localized or non-localized message.
458      * This method will first attempt to find <code>msg</code> in the
459      * properties file, if not found it will print the given msg. The
460      * specified Logger will be used.</p>
461      *
462      * @param loggerId The logger to use. This may be specified as a
463      * String or Class Object.
464      *
465      * @param msg The message (or <code>ResourceBundle</code> key).
466      */

467     public static void fine(Object JavaDoc loggerId, String JavaDoc msg) {
468     getLogger(loggerId).log(Level.FINE, getMessage(msg, false));
469     }
470
471     /**
472      * <p> Logging method to log a <code>Throwable</code> with a message.</p>
473      *
474      * @param msg The message.
475      *
476      * @param ex The <code>Throwable</code> to log.
477      */

478     public static void fine(String JavaDoc msg, Throwable JavaDoc ex) {
479     getLogger().log(Level.FINE, getMessage(msg, false), ex);
480     }
481
482     /**
483      * <p> Logging method to log a <code>Throwable</code> with a
484      * message. The specified Logger will be used.</p>
485      *
486      * @param loggerId The logger to use. This may be specified as a
487      * String or Class Object.
488      *
489      * @param msg The message.
490      *
491      * @param ex The <code>Throwable</code> to log.
492      */

493     public static void fine(Object JavaDoc loggerId, String JavaDoc msg, Throwable JavaDoc ex) {
494     getLogger(loggerId).log(Level.FINE, getMessage(msg, false), ex);
495     }
496
497
498     ////////////////////////////////////////////////////////////
499
// CONFIG LOGGING METHODS
500
////////////////////////////////////////////////////////////
501

502     /**
503      * <p> Method to check if this log level is enabled for the default
504      * logger.</p>
505      *
506      * @return true if the log level is enabled, false otherwise.
507      */

508     public static boolean configEnabled() {
509     return getLogger().isLoggable(Level.CONFIG);
510     }
511
512     /**
513      * <p> Method to check if this log level is enabled for the given
514      * logger.</p>
515      *
516      * @param loggerId The logger to check. This may be specified as a
517      * String or Class Object.
518      *
519      * @return true if the log level is enabled, false otherwise.
520      */

521     public static boolean configEnabled(Object JavaDoc loggerId) {
522     return getLogger(loggerId).isLoggable(Level.CONFIG);
523     }
524
525     /**
526      * <p> Logging method supporting a localized message key and a single
527      * substitution parameter. It will use the default Logger.</p>
528      *
529      * @param msgId The <code>ResourceBundle</code> key used to lookup
530      * the message.
531      *
532      * @param param Value to substitute into the message.
533      *
534      * @see LogUtil#BUNDLE_NAME
535      */

536     public static void config(String JavaDoc msgId, Object JavaDoc param) {
537     config(msgId, new Object JavaDoc[] {param});
538     }
539
540     /**
541      * <p> Logging method supporting a localized message key and zero or more
542      * substitution parameters. It will use the default Logger.</p>
543      *
544      * @param msgId The <code>ResourceBundle</code> key used to lookup
545      * the message.
546      *
547      * @param params Value(s) to substitute into the message.
548      *
549      * @see LogUtil#BUNDLE_NAME
550      */

551     public static void config(String JavaDoc msgId, Object JavaDoc[] params) {
552     getLogger().log(Level.CONFIG, getMessage(msgId, params, false));
553     }
554
555     /**
556      * <p> Logging method supporting a localized message key, a single
557      * substitution parameter, and the ability to specify the Logger.</p>
558      *
559      * @param loggerId The logger to use. This may be specified as a
560      * String or Class Object.
561      *
562      * @param msgId The <code>ResourceBundle</code> key used to lookup
563      * the message.
564      *
565      * @param param Value to substitute into the message.
566      *
567      * @see LogUtil#BUNDLE_NAME
568      */

569     public static void config(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc param) {
570     config(loggerId, msgId, new Object JavaDoc[] {param});
571     }
572
573     /**
574      * <p> Logging method supporting a localized message key, zero or more
575      * substitution parameters, and the ability to specify the Logger.</p>
576      *
577      * @param loggerId The logger to use. This may be specified as a
578      * String or Class Object.
579      *
580      * @param msgId The <code>ResourceBundle</code> key used to lookup
581      * the message.
582      *
583      * @param params Value(s) to substitute into the message.
584      *
585      * @see LogUtil#BUNDLE_NAME
586      */

587     public static void config(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc[] params) {
588     getLogger(loggerId).log(Level.CONFIG, getMessage(msgId, params, false));
589     }
590
591     /**
592      * <p> Logging method to log a simple localized or non-localized message.
593      * This method will first attempt to find <code>msg</code> in the
594      * properties file, if not found it will print the given msg.</p>
595      *
596      * @param msg The message (or <code>ResourceBundle</code> key).
597      */

598     public static void config(String JavaDoc msg) {
599     config(DEFAULT_LOGGER, msg);
600     }
601
602     /**
603      * <p> Logging method to log a simple localized or non-localized message.
604      * This method will first attempt to find <code>msg</code> in the
605      * properties file, if not found it will print the given msg. The
606      * specified Logger will be used.</p>
607      *
608      * @param loggerId The logger to use. This may be specified as a
609      * String or Class Object.
610      *
611      * @param msg The message (or <code>ResourceBundle</code> key).
612      */

613     public static void config(Object JavaDoc loggerId, String JavaDoc msg) {
614     getLogger(loggerId).log(Level.CONFIG, getMessage(msg, false));
615     }
616
617     /**
618      * <p> Logging method to log a <code>Throwable</code> with a
619      * message.</p>
620      *
621      * @param msg The message.
622      *
623      * @param ex The <code>Throwable</code> to log.
624      */

625     public static void config(String JavaDoc msg, Throwable JavaDoc ex) {
626     getLogger().log(Level.CONFIG, getMessage(msg, false), ex);
627     }
628
629     /**
630      * <p> Logging method to log a <code>Throwable</code> with a
631      * message. The specified Logger will be used.</p>
632      *
633      * @param loggerId The logger to use. This may be specified as a
634      * String or Class Object.
635      *
636      * @param msg The message.
637      *
638      * @param ex The <code>Throwable</code> to log.
639      */

640     public static void config(Object JavaDoc loggerId, String JavaDoc msg, Throwable JavaDoc ex) {
641     getLogger(loggerId).log(Level.CONFIG, getMessage(msg, false), ex);
642     }
643
644
645     ////////////////////////////////////////////////////////////
646
// INFO LOGGING METHODS
647
////////////////////////////////////////////////////////////
648

649     /**
650      * <p> Method to check if this log level is enabled for the default
651      * logger.</p>
652      *
653      * @return true if the log level is enabled, false otherwise.
654      */

655     public static boolean infoEnabled() {
656     return getLogger().isLoggable(Level.INFO);
657     }
658
659     /**
660      * <p> Method to check if this log level is enabled for the given
661      * logger.</p>
662      *
663      * @param loggerId The logger to check. This may be specified as a
664      * String or Class Object.
665      *
666      * @return true if the log level is enabled, false otherwise.
667      */

668     public static boolean infoEnabled(Object JavaDoc loggerId) {
669     return getLogger(loggerId).isLoggable(Level.INFO);
670     }
671
672     /**
673      * <p> Logging method to log a simple localized message. The default
674      * Logger will be used.</p>
675      *
676      * @param msgId The <code>ResourceBundle</code> key used to lookup
677      * the message.
678      *
679      * @see LogUtil#BUNDLE_NAME
680      */

681     public static void info(String JavaDoc msgId) {
682     getLogger().log(Level.INFO, getMessage(msgId, true));
683     }
684
685     /**
686      * <p> Logging method to log a simple localized message. The
687      * specified Logger will be used.</p>
688      *
689      * @param loggerId The logger to use. This may be specified as a
690      * String or Class Object.
691      *
692      * @param msgId The <code>ResourceBundle</code> key used to lookup
693      * the message.
694      *
695      * @see LogUtil#BUNDLE_NAME
696      */

697     public static void info(Object JavaDoc loggerId, String JavaDoc msgId) {
698     getLogger(loggerId).log(Level.INFO, getMessage(msgId, true));
699     }
700
701     /**
702      * <p> Logging method supporting a localized message key and a single
703      * substitution parameter. It will use the default Logger.</p>
704      *
705      * @param msgId The <code>ResourceBundle</code> key used to lookup
706      * the message.
707      *
708      * @param param Value to substitute into the message.
709      *
710      * @see LogUtil#BUNDLE_NAME
711      */

712     public static void info(String JavaDoc msgId, Object JavaDoc param) {
713     info(msgId, new Object JavaDoc[] {param});
714     }
715
716     /**
717      * <p> Logging method supporting a localized message key and zero or more
718      * substitution parameters. It will use the default Logger.</p>
719      *
720      * @param msgId The <code>ResourceBundle</code> key used to lookup
721      * the message.
722      *
723      * @param params Value(s) to substitute into the message.
724      *
725      * @see LogUtil#BUNDLE_NAME
726      */

727     public static void info(String JavaDoc msgId, Object JavaDoc[] params) {
728     getLogger().log(Level.INFO, getMessage(msgId, params, true));
729     }
730
731     /**
732      * <p> Logging method supporting a localized message key, a single
733      * substitution parameter, and the ability to specify the Logger.</p>
734      *
735      * @param loggerId The logger to use. This may be specified as a
736      * String or Class Object.
737      *
738      * @param msgId The <code>ResourceBundle</code> key used to lookup
739      * the message.
740      *
741      * @param param Value to substitute into the message.
742      *
743      * @see LogUtil#BUNDLE_NAME
744      */

745     public static void info(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc param) {
746     info(loggerId, msgId, new Object JavaDoc[] {param});
747     }
748
749     /**
750      * <p> Logging method supporting a localized message key, zero or more
751      * substitution parameters, and the ability to specify the Logger.</p>
752      *
753      * @param loggerId The logger to use. This may be specified as a
754      * String or Class Object.
755      *
756      * @param msgId The <code>ResourceBundle</code> key used to lookup
757      * the message.
758      *
759      * @param params Value(s) to substitute into the message.
760      *
761      * @see LogUtil#BUNDLE_NAME
762      */

763     public static void info(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc[] params) {
764     getLogger(loggerId).log(Level.INFO, getMessage(msgId, params, true));
765     }
766
767     /**
768      * <p> Logging method to log a <code>Throwable</code> with a localized
769      * message.</p>
770      *
771      * @param msgId The <code>ResourceBundle</code> key used to lookup
772      * the message.
773      *
774      * @param ex The <code>Throwable</code> to log.
775      *
776      * @see LogUtil#BUNDLE_NAME
777      */

778     public static void info(String JavaDoc msgId, Throwable JavaDoc ex) {
779     getLogger().log(Level.INFO, getMessage(msgId, false), ex);
780     }
781
782     /**
783      * <p> Logging method to log a <code>Throwable</code> with a localized
784      * message. The specified Logger will be used.</p>
785      *
786      * @param loggerId The logger to use. This may be specified as a
787      * String or Class Object.
788      *
789      * @param msgId The <code>ResourceBundle</code> key used to lookup
790      * the message.
791      *
792      * @param ex The <code>Throwable</code> to log.
793      *
794      * @see LogUtil#BUNDLE_NAME
795      */

796     public static void info(Object JavaDoc loggerId, String JavaDoc msgId, Throwable JavaDoc ex) {
797     getLogger(loggerId).log(Level.INFO, getMessage(msgId, false), ex);
798     }
799
800
801     ////////////////////////////////////////////////////////////
802
// WARNING LOGGING METHODS
803
////////////////////////////////////////////////////////////
804

805     /**
806      * <p> Method to check if this log level is enabled for the default
807      * logger.</p>
808      *
809      * @return true if the log level is enabled, false otherwise.
810      */

811     public static boolean warningEnabled() {
812     return getLogger().isLoggable(Level.WARNING);
813     }
814
815     /**
816      * <p> Method to check if this log level is enabled for the given
817      * logger.</p>
818      *
819      * @param loggerId The logger to check. This may be specified as a
820      * String or Class Object.
821      *
822      * @return true if the log level is enabled, false otherwise.
823      */

824     public static boolean warningEnabled(Object JavaDoc loggerId) {
825     return getLogger(loggerId).isLoggable(Level.WARNING);
826     }
827
828     /**
829      * <p> Logging method to log a simple localized message. The default
830      * Logger will be used.</p>
831      *
832      * @param msgId The <code>ResourceBundle</code> key used to lookup
833      * the message.
834      *
835      * @see LogUtil#BUNDLE_NAME
836      */

837     public static void warning(String JavaDoc msgId) {
838     getLogger().log(Level.WARNING, getMessage(msgId, true));
839     }
840
841     /**
842      * <p> Logging method to log a simple localized message. The
843      * specified Logger will be used.</p>
844      *
845      * @param loggerId The logger to use. This may be specified as a
846      * String or Class Object.
847      *
848      * @param msgId The <code>ResourceBundle</code> key used to lookup
849      * the message.
850      *
851      * @see LogUtil#BUNDLE_NAME
852      */

853     public static void warning(Object JavaDoc loggerId, String JavaDoc msgId) {
854     getLogger(loggerId).log(Level.WARNING, getMessage(msgId, true));
855     }
856
857     /**
858      * <p> Logging method supporting a localized message key and a single
859      * substitution parameter. It will use the default Logger.</p>
860      *
861      * @param msgId The <code>ResourceBundle</code> key used to lookup
862      * the message.
863      *
864      * @param param Value to substitute into the message.
865      *
866      * @see LogUtil#BUNDLE_NAME
867      */

868     public static void warning(String JavaDoc msgId, Object JavaDoc param) {
869     warning(msgId, new Object JavaDoc[] {param});
870     }
871
872     /**
873      * <p> Logging method supporting a localized message key and zero or more
874      * substitution parameters. It will use the default Logger.</p>
875      *
876      * @param msgId The <code>ResourceBundle</code> key used to lookup
877      * the message.
878      *
879      * @param params Value(s) to substitute into the message.
880      *
881      * @see LogUtil#BUNDLE_NAME
882      */

883     public static void warning(String JavaDoc msgId, Object JavaDoc[] params) {
884     getLogger().log(Level.WARNING, getMessage(msgId, params, true));
885     }
886
887     /**
888      * <p> Logging method supporting a localized message key, a single
889      * substitution parameter, and the ability to specify the Logger.</p>
890      *
891      * @param loggerId The logger to use. This may be specified as a
892      * String or Class Object.
893      *
894      * @param msgId The <code>ResourceBundle</code> key used to lookup
895      * the message.
896      *
897      * @param param Value to substitute into the message.
898      *
899      * @see LogUtil#BUNDLE_NAME
900      */

901     public static void warning(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc param) {
902     warning(loggerId, msgId, new Object JavaDoc[] {param});
903     }
904
905     /**
906      * <p> Logging method supporting a localized message key, zero or more
907      * substitution parameters, and the ability to specify the Logger.</p>
908      *
909      * @param loggerId The logger to use. This may be specified as a
910      * String or Class Object.
911      *
912      * @param msgId The <code>ResourceBundle</code> key used to lookup
913      * the message.
914      *
915      * @param params Value(s) to substitute into the message.
916      *
917      * @see LogUtil#BUNDLE_NAME
918      */

919     public static void warning(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc[] params) {
920     getLogger(loggerId).log(Level.WARNING, getMessage(msgId, params, true));
921     }
922
923     /**
924      * <p> Logging method to log a <code>Throwable</code> with a localized
925      * message.</p>
926      *
927      * @param msgId The <code>ResourceBundle</code> key used to lookup
928      * the message.
929      *
930      * @param ex The <code>Throwable</code> to log.
931      *
932      * @see LogUtil#BUNDLE_NAME
933      */

934     public static void warning(String JavaDoc msgId, Throwable JavaDoc ex) {
935     getLogger().log(Level.WARNING, getMessage(msgId, false), ex);
936     }
937
938     /**
939      * <p> Logging method to log a <code>Throwable</code> with a localized
940      * message. The specified Logger will be used.</p>
941      *
942      * @param loggerId The logger to use. This may be specified as a
943      * String or Class Object.
944      *
945      * @param msgId The <code>ResourceBundle</code> key used to lookup
946      * the message.
947      *
948      * @param ex The <code>Throwable</code> to log.
949      *
950      * @see LogUtil#BUNDLE_NAME
951      */

952     public static void warning(Object JavaDoc loggerId, String JavaDoc msgId, Throwable JavaDoc ex) {
953     getLogger(loggerId).log(Level.WARNING, getMessage(msgId, false), ex);
954     }
955
956
957     ////////////////////////////////////////////////////////////
958
// SEVERE LOGGING METHODS
959
////////////////////////////////////////////////////////////
960

961     /**
962      * <p> Method to check if this log level is enabled for the default
963      * logger.</p>
964      *
965      * @return true if the log level is enabled, false otherwise.
966      */

967     public static boolean severeEnabled() {
968     return getLogger().isLoggable(Level.SEVERE);
969     }
970
971     /**
972      * <p> Method to check if this log level is enabled for the given
973      * logger.</p>
974      *
975      * @param loggerId The logger to check. This may be specified as a
976      * String or Class Object.
977      *
978      * @return true if the log level is enabled, false otherwise.
979      */

980     public static boolean severeEnabled(Object JavaDoc loggerId) {
981     return getLogger(loggerId).isLoggable(Level.SEVERE);
982     }
983
984     /**
985      * <p> Logging method to log a simple localized message. The default
986      * Logger will be used.</p>
987      *
988      * @param msgId The <code>ResourceBundle</code> key used to lookup
989      * the message.
990      *
991      * @see LogUtil#BUNDLE_NAME
992      */

993     public static void severe(String JavaDoc msgId) {
994     getLogger().log(Level.SEVERE, getMessage(msgId, true));
995     }
996
997     /**
998      * <p> Logging method to log a simple localized message. The
999      * specified Logger will be used.</p>
1000     *
1001     * @param loggerId The logger to use. This may be specified as a
1002     * String or Class Object.
1003     *
1004     * @param msgId The <code>ResourceBundle</code> key used to lookup
1005     * the message.
1006     *
1007     * @see LogUtil#BUNDLE_NAME
1008     */

1009    public static void severe(Object JavaDoc loggerId, String JavaDoc msgId) {
1010    getLogger(loggerId).log(Level.SEVERE, getMessage(msgId, true));
1011    }
1012
1013    /**
1014     * <p> Logging method supporting a localized message key and a single
1015     * substitution parameter. It will use the default Logger.</p>
1016     *
1017     * @param msgId The <code>ResourceBundle</code> key used to lookup
1018     * the message.
1019     *
1020     * @param param Value to substitute into the message.
1021     *
1022     * @see LogUtil#BUNDLE_NAME
1023     */

1024    public static void severe(String JavaDoc msgId, Object JavaDoc param) {
1025    severe(msgId, new Object JavaDoc[] {param});
1026    }
1027
1028    /**
1029     * <p> Logging method supporting a localized message key and zero or more
1030     * substitution parameters. It will use the default Logger.</p>
1031     *
1032     * @param msgId The <code>ResourceBundle</code> key used to lookup
1033     * the message.
1034     *
1035     * @param params Value(s) to substitute into the message.
1036     *
1037     * @see LogUtil#BUNDLE_NAME
1038     */

1039    public static void severe(String JavaDoc msgId, Object JavaDoc[] params) {
1040    getLogger().log(Level.SEVERE, getMessage(msgId, params, true));
1041    }
1042
1043    /**
1044     * <p> Logging method supporting a localized message key, a single
1045     * substitution parameter, and the ability to specify the Logger.</p>
1046     *
1047     * @param loggerId The logger to use. This may be specified as a
1048     * String or Class Object.
1049     *
1050     * @param msgId The <code>ResourceBundle</code> key used to lookup
1051     * the message.
1052     *
1053     * @param param Value to substitute into the message.
1054     *
1055     * @see LogUtil#BUNDLE_NAME
1056     */

1057    public static void severe(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc param) {
1058    severe(loggerId, msgId, new Object JavaDoc[] {param});
1059    }
1060
1061    /**
1062     * <p> Logging method supporting a localized message key, zero or more
1063     * substitution parameters, and the ability to specify the Logger.</p>
1064     *
1065     * @param loggerId The logger to use. This may be specified as a
1066     * String or Class Object.
1067     *
1068     * @param msgId The <code>ResourceBundle</code> key used to lookup
1069     * the message.
1070     *
1071     * @param params Value(s) to substitute into the message.
1072     *
1073     * @see LogUtil#BUNDLE_NAME
1074     */

1075    public static void severe(Object JavaDoc loggerId, String JavaDoc msgId, Object JavaDoc[] params) {
1076    getLogger(loggerId).log(Level.SEVERE, getMessage(msgId, params, true));
1077    }
1078
1079    /**
1080     * <p> Logging method to log a <code>Throwable</code> with a localized
1081     * message.</p>
1082     *
1083     * @param msgId The <code>ResourceBundle</code> key used to lookup
1084     * the message.
1085     *
1086     * @param ex The <code>Throwable</code> to log.
1087     *
1088     * @see LogUtil#BUNDLE_NAME
1089     */

1090    public static void severe(String JavaDoc msgId, Throwable JavaDoc ex) {
1091    getLogger().log(Level.SEVERE, getMessage(msgId, false), ex);
1092    }
1093
1094    /**
1095     * <p> Logging method to log a <code>Throwable</code> with a localized
1096     * message. The specified Logger will be used.</p>
1097     *
1098     * @param loggerId The logger to use. This may be specified as a
1099     * String or Class Object.
1100     *
1101     * @param msgId The <code>ResourceBundle</code> key used to lookup
1102     * the message.
1103     *
1104     * @param ex The <code>Throwable</code> to log.
1105     *
1106     * @see LogUtil#BUNDLE_NAME
1107     */

1108    public static void severe(Object JavaDoc loggerId, String JavaDoc msgId, Throwable JavaDoc ex) {
1109    getLogger(loggerId).log(Level.SEVERE, getMessage(msgId, false), ex);
1110    }
1111
1112
1113    ////////////////////////////////////////////////////////////
1114
// Misc methods
1115
////////////////////////////////////////////////////////////
1116

1117    /**
1118     * <p> This method provides direct access to the default Logger. It is
1119     * private because the internals of what type of logger is being used
1120     * should not be exposed outside this class.</p>
1121     */

1122    private static Logger JavaDoc getLogger() {
1123    return DEFAULT_LOGGER;
1124    }
1125
1126    /**
1127     * <p> This method provides direct access to the Logger. It is private
1128     * because the internals of what type of logger is being used should
1129     * not be exposed outside this class.</p>
1130     *
1131     * <p> This method will return the default logger (if INFO), or delegate
1132     * to {@link #getLogger(String)} or {@link #getLogger(Class)}.</p>
1133     *
1134     * @param key The logger to use as specified by the Object.
1135     */

1136    private static Logger JavaDoc getLogger(Object JavaDoc key) {
1137    // If null, use default
1138
if (key == null) {
1139        return getLogger();
1140    }
1141
1142    // If string, use it as logger name
1143
if (key instanceof String JavaDoc) {
1144        return getLogger((String JavaDoc) key);
1145    }
1146
1147    // If Log, return it
1148
if (key instanceof Logger JavaDoc) {
1149        return (Logger JavaDoc) key;
1150    }
1151
1152    // If class, use it
1153
if (key instanceof Class JavaDoc) {
1154        return getLogger((Class JavaDoc) key);
1155    }
1156
1157    // else, use the class name
1158
return getLogger(key.getClass());
1159    }
1160
1161    /**
1162     * <p> This method provides direct access to the Logger. It is private
1163     * because the internals of what type of logger is being used should
1164     * not be exposed outside this class.</p>
1165     *
1166     * @param key The logger to use as specified by the String.
1167     */

1168    private static Logger JavaDoc getLogger(String JavaDoc key) {
1169    if (key.trim().length() == 0) {
1170        return DEFAULT_LOGGER;
1171    }
1172    return Logger.getLogger(key);
1173    }
1174
1175    /**
1176     * <p> This method provides direct access to the Logger. It is private
1177     * because the internals of what type of logger is being used should
1178     * not be exposed outside this class.</p>
1179     *
1180     * @param key The logger to use as specified by the Class.
1181     */

1182    private static Logger JavaDoc getLogger(Class JavaDoc key) {
1183    if (key == null) {
1184        return DEFAULT_LOGGER;
1185    }
1186    return Logger.getLogger(key.getName());
1187    }
1188
1189    /**
1190     * <p> This method gets the appropriate message to display. It will
1191     * attempt to resolve it from the <code>ResourceBundle</code>.
1192     * If not found and it will either use the message id as the key,
1193     * or it will return an error message depending on whether
1194     * <code>strict</code> is true or false.</p>
1195     *
1196     * @param msgId The message key
1197     * @param strict True if key not found should be an error
1198     *
1199     * @return The message to write to the log file.
1200     */

1201    private static String JavaDoc getMessage(String JavaDoc msgId, boolean strict) {
1202    return getMessage(msgId, new Object JavaDoc[0], strict);
1203    }
1204
1205    /**
1206     * <p> This method gets the appropriate message to display. It will
1207     * attempt to resolve it from the <code>ResourceBundle</code>.
1208     * If not found and it will either use the message id as the key,
1209     * or it will return an error message depending on whether
1210     * <code>strict</code> is true or false.</p>
1211     *
1212     * @param msgId The message key
1213     * @param params The parameters
1214     * @param strict True if key not found should be an error
1215     *
1216     * @return The message to write to the log file.
1217     */

1218    private static String JavaDoc getMessage(
1219        String JavaDoc msgId, Object JavaDoc[] params, boolean strict) {
1220    String JavaDoc result = MessageUtil.getMessage(BUNDLE_NAME, msgId, params);
1221    if (result.equals(msgId)) {
1222        // We didn't find the key...
1223
if (strict) {
1224        // A key is required, return an error message
1225
if (msgId.equals(KEY_NOT_FOUND_KEY)) {
1226            // This is here to prevent and infinite loop
1227
result = KEY_NOT_FOUND_KEY + LOG_KEY_MESSAGE_SEPARATOR
1228            + "'" + params[0] + "' not found in ResourceBundle: '"
1229            + BUNDLE_NAME + "'";
1230        } else {
1231            result = getMessage(
1232                KEY_NOT_FOUND_KEY, new Object JavaDoc[] {msgId}, strict);
1233        }
1234        } else {
1235        // Use the msgId as the message, use the default key
1236
result = DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msgId;
1237        }
1238    } else {
1239        // We found the key, construct the log format...
1240
result = msgId + LOG_KEY_MESSAGE_SEPARATOR + result;
1241    }
1242
1243    // Return the formatted result
1244
return result;
1245    }
1246
1247    /**
1248     * <p> This is the bundle name for the <code>ResourceBundle</code> that
1249     * contains all the message strings.</p>
1250     */

1251    public static final String JavaDoc BUNDLE_NAME =
1252        "com.sun.enterprise.tools.jsfext.resource.LogMessages";
1253
1254    /**
1255     * <p> This is the default log key.</p>
1256     */

1257    public static final String JavaDoc DEFAULT_LOG_KEY = "WEBUI0001";
1258
1259    /**
1260     * <p> This is the default logger name.</p>
1261     */

1262    public static final String JavaDoc DEFAULT_LOGGER_NAME =
1263        "com.sun.enterprise.tools.jsfext";
1264
1265    /**
1266     * <p> This key is used when the requested key is not found to inform the
1267     * developer they forgot to add a key.</p>
1268     */

1269    public static final String JavaDoc KEY_NOT_FOUND_KEY = "WEBUI0002";
1270
1271
1272    /**
1273     * <p> The default Logger.</p>
1274     */

1275    private static final Logger JavaDoc DEFAULT_LOGGER = getLogger(DEFAULT_LOGGER_NAME);
1276
1277    /**
1278     * <p> This is the separator between the the log key and log message.</p>
1279     */

1280    private static final String JavaDoc LOG_KEY_MESSAGE_SEPARATOR = ": ";
1281
1282}
1283
Popular Tags