1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.logging;
20
21 import java.text.MessageFormat;
22 import java.util.Locale;
23 import java.util.MissingResourceException;
24 import java.util.ResourceBundle;
25 import java.util.logging.Handler;
26 import java.util.logging.Level;
27 import java.util.logging.LogRecord;
28 import java.util.logging.Logger;
29
30 import javax.faces.application.Resource;
31
32 /**
33 * MyfacesLogger wraps JDK 1.4 logging to provided a large number of
34 * extra convenience methods. MyfacesLoggers are created off of
35 * Packages or Classes (not arbitrary names) to force
36 * proper logging hierarchies.
37 *
38 * Has predefined Logger for javax.faces related packages, like {@link MyfacesLogger#APPLICATION_LOGGER} for javax.faces.application and related
39 *
40 * Original code copied from TrinidadLogger
41 *
42 */
43 public class MyfacesLogger
44 {
45
46 private static final String LOGGER_NAME_PREFIX = "org.apache.myfaces.";
47
48 /** for javax.faces.application and related */
49 public static final MyfacesLogger APPLICATION_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "application");
50
51 /** for javax.faces.component and related */
52 public static final MyfacesLogger COMPONENT_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "component");
53
54 /** for javax.faces.component.html and related */
55 public static final MyfacesLogger COMPONENT_HTML_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "component.html");
56
57 /** for javax.faces.component.behavior and related */
58 public static final MyfacesLogger COMPONENT_BEHAVIOR_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "component.behavior");
59
60 /** for javax.faces.component.visit and related */
61 public static final MyfacesLogger COMPONENT_VISIT_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "component.visit");
62
63 /** for javax.faces.context and related */
64 public static final MyfacesLogger CONTEXT_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "context");
65
66 /** for javax.faces.convert and related */
67 public static final MyfacesLogger CONVERT_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "convert");
68
69 /** for javax.faces.event and related */
70 public static final MyfacesLogger EVENT_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "event");
71
72 /** for javax.faces.lifecycle and related */
73 public static final MyfacesLogger LIFECYCLE_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "lifecycle");
74
75 /** for javax.faces.model and related */
76 public static final MyfacesLogger MODEL_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "model");
77
78 /** for javax.faces.render and related */
79 public static final MyfacesLogger RENDER_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "render");
80
81 /** for javax.faces.validator and related */
82 public static final MyfacesLogger VALIDATOR_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "validator");
83
84 /** for javax.faces.view and related */
85 public static final MyfacesLogger VIEW_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "view");
86
87 /** for javax.faces.view.facelets and related */
88 public static final MyfacesLogger VIEW_FACELETS_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "view.facelets");
89
90 /** for {@link Resource} and related (does not have own javax.faces. package) */
91 public static final MyfacesLogger RESOURCE_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "resource");
92
93 /** for myfaces config */
94 public static final MyfacesLogger CONFIG_LOGGER = MyfacesLogger.createMyfacesLogger(LOGGER_NAME_PREFIX + "config");
95
96
97 private MyfacesLogger(Logger log)
98 {
99 _log = log;
100 }
101
102 /**
103 * Get the Java logger from an Myfaces Logger.
104 *
105 * @return a java Logger instance
106 */
107 public Logger getLogger()
108 {
109 return _log;
110 }
111
112 /**
113 * Find or create a logger for a named subsystem. If a logger has
114 * already been created with the given name it is returned. Otherwise
115 * a new logger is created.
116 * <p>
117 * If a new logger is created its log level will be configured
118 * based on the LogManager configuration and it will configured
119 * to also send logging output to its parent's handlers. It will
120 * be registered in the LogManager global namespace.
121 *
122 * @param name A name for the logger. This should
123 * be a dot-separated name and should normally
124 * be based on the package name or class name
125 * of the subsystem, such as java.net
126 * or javax.swing
127 * @return a suitable Logger
128 */
129 private static MyfacesLogger createMyfacesLogger(String name)
130 {
131 if (name == null)
132 throw new IllegalArgumentException(_LOG.getMessage(
133 "LOGGER_NAME_REQUIRED"));
134
135 Logger log;
136
137 if (name.startsWith("javax.faces"))
138 {
139 log = Logger.getLogger(name, _API_LOGGER_BUNDLE);
140 }
141 else if (name.startsWith("org.apache.myfaces."))
142 {
143 log = Logger.getLogger(name, _IMPL_LOGGER_BUNDLE);
144 }
145 else
146 {
147 log = Logger.getLogger(name);
148 }
149
150 return new MyfacesLogger(log);
151 }
152
153 /**
154 * Find or create a logger for a named subsystem. If a logger has
155 * already been created with the given name it is returned. Otherwise
156 * a new logger is created.
157 * <p>
158 * If a new logger is created its log level will be configured
159 * based on the LogManager and it will configured to also send logging
160 * output to its parent loggers Handlers. It will be registered in
161 * the LogManager global namespace.
162 * <p>
163 * If the named Logger already exists and does not yet have a
164 * localization resource bundle then the given resource bundle
165 * name is used. If the named Logger already exists and has
166 * a different resource bundle name then an IllegalArgumentException
167 * is thrown.
168 * <p>
169 * @param name A name for the logger. This should
170 * be a dot-separated name and should normally
171 * be based on the package name or class name
172 * of the subsystem, such as java.net
173 * or javax.swing
174 * @param resourceBundleName name of ResourceBundle to be used for localizing
175 * messages for this logger.
176 * @return a suitable Logger
177 * @throws MissingResourceException if the named ResourceBundle cannot be found.
178 * @throws IllegalArgumentException if the Logger already exists and uses
179 * a different resource bundle name.
180 */
181 private static MyfacesLogger createMyfacesLogger(String name, String resourceBundleName)
182 {
183 if (name == null)
184 throw new IllegalArgumentException(_LOG.getMessage(
185 "LOGGER_NAME_REQUIRED"));
186
187 Logger log = Logger.getLogger(name, resourceBundleName);
188
189 return new MyfacesLogger(log);
190 }
191
192
193 /**
194 * Find or create a logger for a named subsystem. If a logger has
195 * already been created with the given name it is returned. Otherwise
196 * a new logger is created.
197 * <p>
198 * If a new logger is created its log level will be configured
199 * based on the LogManager configuration and it will configured
200 * to also send logging output to its parent's handlers. It will
201 * be registered in the LogManager global namespace.
202 *
203 * @param c A class instance for the logger.
204 * @return a suitable Logger
205 */
206 public static MyfacesLogger createMyfacesLogger(Class<?> c)
207 {
208 if (c == null)
209 throw new IllegalArgumentException(_LOG.getMessage(
210 "CLASS_REQUIRED"));
211 String name = c.getName();
212 return createMyfacesLogger(name);
213 }
214
215 /**
216 * Find or create a logger for a named subsystem. If a logger has
217 * already been created with the given name it is returned. Otherwise
218 * a new logger is created.
219 * <p>
220 * If a new logger is created its log level will be configured
221 * based on the LogManager configuration and it will configured
222 * to also send logging output to its parent's handlers. It will
223 * be registered in the LogManager global namespace.
224 *
225 * @param c A class instance for the logger.
226 * @param resourceBundleName name of ResourceBundle to be used for localizing
227 * messages for this logger.
228 *
229 * @return a suitable Logger
230 */
231 public static MyfacesLogger createMyfacesLogger(Class<?> c, String resourceBundleName)
232 {
233 if (c == null)
234 throw new IllegalArgumentException(_LOG.getMessage(
235 "CLASS_REQUIRED"));
236 String name = c.getName();
237 return createMyfacesLogger(name, resourceBundleName);
238 }
239
240 /**
241 * Find or create a logger for a named subsystem. If a logger has
242 * already been created with the given name it is returned. Otherwise
243 * a new logger is created.
244 * <p>
245 * If a new logger is created its log level will be configured
246 * based on the LogManager configuration and it will configured
247 * to also send logging output to its parent's handlers. It will
248 * be registered in the LogManager global namespace.
249 *
250 * @param p A Package instance for the logger.
251 * @return a suitable Logger
252 */
253
254 public static MyfacesLogger createMyfacesLogger(Package p)
255 {
256 if (p == null)
257 throw new IllegalArgumentException(_LOG.getMessage(
258 "PACKAGE_REQUIRED"));
259 String name = p.getName();
260 return createMyfacesLogger(name);
261 }
262
263 /**
264 * Find or create a logger for a named subsystem. If a logger has
265 * already been created with the given name it is returned. Otherwise
266 * a new logger is created.
267 * <p>
268 * If a new logger is created its log level will be configured
269 * based on the LogManager configuration and it will configured
270 * to also send logging output to its parent's handlers. It will
271 * be registered in the LogManager global namespace.
272 *
273 * @param p A Package instance for the logger.
274 * @param resourceBundleName name of ResourceBundle to be used for localizing
275 * messages for this logger.
276 *
277 * @return a suitable Logger
278 */
279
280 public static MyfacesLogger createMyfacesLogger(Package p, String resourceBundleName)
281 {
282 if (p == null)
283 throw new IllegalArgumentException(_LOG.getMessage(
284 "PACKAGE_REQUIRED"));
285 String name = p.getName();
286 return createMyfacesLogger(name, resourceBundleName);
287 }
288
289 /**
290 * Log a LogRecord.
291 * <p>
292 * All the other logging methods in this class call through
293 * this method to actually perform any logging. Subclasses can
294 * override this single method to capture all log activity.
295 *
296 * @param record the LogRecord to be published
297 */
298 public void log(LogRecord record)
299 {
300 _log.log(record);
301 }
302
303
304 //================================================================
305 // Start of convenience methods WITHOUT className and methodName
306 //================================================================
307
308 /**
309 * Log a message, with no arguments.
310 * <p>
311 * If the logger is currently enabled for the given message
312 * level then the given message is forwarded to all the
313 * registered output Handler objects.
314 * <p>
315 * @param msg The string message (or a key in the message catalog)
316 */
317 public void log(String msg)
318 {
319 log(Level.FINE, msg);
320 }
321
322 /**
323 * Log a message, with no arguments.
324 * <p>
325 * If the logger is currently enabled for the given message
326 * level then the given message is forwarded to all the
327 * registered output Handler objects.
328 * <p>
329 * @param level One of the message level identifiers, e.g. SEVERE
330 * @param msg The string message (or a key in the message catalog)
331 */
332 public void log(Level level, String msg)
333 {
334 if (isLoggable(level))
335 {
336 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
337 doLog(lr);
338 }
339 }
340
341 /**
342 * Log a message, with one object parameter.
343 * <p>
344 * If the logger is currently enabled for the given message
345 * level then a corresponding LogRecord is created and forwarded
346 * to all the registered output Handler objects.
347 * <p>
348 * @param level One of the message level identifiers, e.g. SEVERE
349 * @param msg The string message (or a key in the message catalog)
350 * @param param1 parameter to the message
351 */
352 public void log(Level level, String msg, Object param1)
353 {
354 if (isLoggable(level))
355 {
356 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
357 Object params[] = { param1};
358 lr.setParameters(params);
359 doLog(lr);
360 }
361 }
362
363 /**
364 * Log a message, with an array of object arguments.
365 * <p>
366 * If the logger is currently enabled for the given message
367 * level then a corresponding LogRecord is created and forwarded
368 * to all the registered output Handler objects.
369 * <p>
370 * @param level One of the message level identifiers, e.g. SEVERE
371 * @param msg The string message (or a key in the message catalog)
372 * @param params array of parameters to the message
373 */
374 public void log(Level level, String msg, Object params[])
375 {
376 if (isLoggable(level))
377 {
378 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
379 lr.setParameters(params);
380 doLog(lr);
381 }
382 }
383
384 /**
385 * Log a message, with associated Throwable information.
386 * <p>
387 * If the logger is currently enabled for the given message
388 * level then the given arguments are stored in a LogRecord
389 * which is forwarded to all registered output handlers.
390 * <p>
391 * Note that the thrown argument is stored in the LogRecord thrown
392 * property, rather than the LogRecord parameters property. Thus is it
393 * processed specially by output Formatters and is not treated
394 * as a formatting parameter to the LogRecord message property.
395 * <p>
396 * @param level One of the message level identifiers, e.g. SEVERE
397 * @param msg The string message (or a key in the message catalog)
398 * @param thrown Throwable associated with log message.
399 */
400 public void log(Level level, String msg, Throwable thrown)
401 {
402 if (isLoggable(level))
403 {
404 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
405 lr.setThrown(thrown);
406 doLog(lr);
407 }
408 }
409
410 //================================================================
411 // Start of convenience methods WITH className and methodName
412 //================================================================
413
414 /**
415 * Log a message, specifying source class and method,
416 * with no arguments.
417 * <p>
418 * If the logger is currently enabled for the given message
419 * level then the given message is forwarded to all the
420 * registered output Handler objects.
421 * <p>
422 * @param level One of the message level identifiers, e.g. SEVERE
423 * @param sourceClass name of class that issued the logging request
424 * @param sourceMethod name of method that issued the logging request
425 * @param msg The string message (or a key in the message catalog)
426 */
427 public void logp(Level level, String sourceClass, String sourceMethod, String msg)
428 {
429 if (isLoggable(level))
430 {
431 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
432 lr.setSourceClassName(sourceClass);
433 lr.setSourceMethodName(sourceMethod);
434 doLog(lr);
435 }
436 }
437
438 /**
439 * Log a message, specifying source class and method,
440 * with a single object parameter to the log message.
441 * <p>
442 * If the logger is currently enabled for the given message
443 * level then a corresponding LogRecord is created and forwarded
444 * to all the registered output Handler objects.
445 * <p>
446 * @param level One of the message level identifiers, e.g. SEVERE
447 * @param sourceClass name of class that issued the logging request
448 * @param sourceMethod name of method that issued the logging request
449 * @param msg The string message (or a key in the message catalog)
450 * @param param1 Parameter to the log message.
451 */
452 public void logp(Level level, String sourceClass, String sourceMethod,
453 String msg, Object param1)
454 {
455 if (isLoggable(level))
456 {
457 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
458 lr.setSourceClassName(sourceClass);
459 lr.setSourceMethodName(sourceMethod);
460 Object params[] = { param1};
461 lr.setParameters(params);
462 doLog(lr);
463 }
464 }
465
466 /**
467 * Log a message, specifying source class and method,
468 * with an array of object arguments.
469 * <p>
470 * If the logger is currently enabled for the given message
471 * level then a corresponding LogRecord is created and forwarded
472 * to all the registered output Handler objects.
473 * <p>
474 * @param level One of the message level identifiers, e.g. SEVERE
475 * @param sourceClass name of class that issued the logging request
476 * @param sourceMethod name of method that issued the logging request
477 * @param msg The string message (or a key in the message catalog)
478 * @param params Array of parameters to the message
479 */
480 public void logp(Level level, String sourceClass, String sourceMethod,
481 String msg, Object params[])
482 {
483 if (isLoggable(level))
484 {
485 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
486 lr.setSourceClassName(sourceClass);
487 lr.setSourceMethodName(sourceMethod);
488 lr.setParameters(params);
489 doLog(lr);
490 }
491 }
492
493 /**
494 * Log a message, specifying source class and method,
495 * with associated Throwable information.
496 * <p>
497 * If the logger is currently enabled for the given message
498 * level then the given arguments are stored in a LogRecord
499 * which is forwarded to all registered output handlers.
500 * <p>
501 * Note that the thrown argument is stored in the LogRecord thrown
502 * property, rather than the LogRecord parameters property. Thus is it
503 * processed specially by output Formatters and is not treated
504 * as a formatting parameter to the LogRecord message property.
505 * <p>
506 * @param level One of the message level identifiers, e.g. SEVERE
507 * @param sourceClass name of class that issued the logging request
508 * @param sourceMethod name of method that issued the logging request
509 * @param msg The string message (or a key in the message catalog)
510 * @param thrown Throwable associated with log message.
511 */
512 public void logp(Level level, String sourceClass, String sourceMethod,
513 String msg, Throwable thrown)
514 {
515 if (isLoggable(level))
516 {
517 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
518 lr.setSourceClassName(sourceClass);
519 lr.setSourceMethodName(sourceMethod);
520 lr.setThrown(thrown);
521 doLog(lr);
522 }
523 }
524
525
526 /**
527 * Log a message, specifying source class, method, and resource bundle name
528 * with no arguments.
529 * <p>
530 * If the logger is currently enabled for the given message
531 * level then the given message is forwarded to all the
532 * registered output Handler objects.
533 * <p>
534 * The msg string is localized using the named resource bundle. If the
535 * resource bundle name is null, then the msg string is not localized.
536 * <p>
537 * @param level One of the message level identifiers, e.g. SEVERE
538 * @param sourceClass name of class that issued the logging request
539 * @param sourceMethod name of method that issued the logging request
540 * @param bundleName name of resource bundle to localize msg
541 * @param msg The string message (or a key in the message catalog)
542 * @throws MissingResourceException if no suitable ResourceBundle can
543 * be found.
544 */
545
546 public void logrb(Level level, String sourceClass, String sourceMethod,
547 String bundleName, String msg)
548 {
549 if (isLoggable(level))
550 {
551 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
552 lr.setSourceClassName(sourceClass);
553 lr.setSourceMethodName(sourceMethod);
554 doLog(lr,bundleName);
555 }
556 }
557
558 /**
559 * Log a message, specifying source class, method, and resource bundle name,
560 * with a single object parameter to the log message.
561 * <p>
562 * If the logger is currently enabled for the given message
563 * level then a corresponding LogRecord is created and forwarded
564 * to all the registered output Handler objects.
565 * <p>
566 * The msg string is localized using the named resource bundle. If the
567 * resource bundle name is null, then the msg string is not localized.
568 * <p>
569 * @param level One of the message level identifiers, e.g. SEVERE
570 * @param sourceClass name of class that issued the logging request
571 * @param sourceMethod name of method that issued the logging request
572 * @param bundleName name of resource bundle to localize msg
573 * @param msg The string message (or a key in the message catalog)
574 * @param param1 Parameter to the log message.
575 * @throws MissingResourceException if no suitable ResourceBundle can
576 * be found.
577 */
578 public void logrb(Level level, String sourceClass, String sourceMethod,
579 String bundleName, String msg, Object param1)
580 {
581 if (isLoggable(level))
582 {
583 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
584 lr.setSourceClassName(sourceClass);
585 lr.setSourceMethodName(sourceMethod);
586 Object params[] = { param1};
587 lr.setParameters(params);
588 doLog(lr,bundleName);
589 }
590 }
591
592 /**
593 * Log a message, specifying source class, method, and resource bundle name,
594 * with an array of object arguments.
595 * <p>
596 * If the logger is currently enabled for the given message
597 * level then a corresponding LogRecord is created and forwarded
598 * to all the registered output Handler objects.
599 * <p>
600 * The msg string is localized using the named resource bundle. If the
601 * resource bundle name is null, then the msg string is not localized.
602 * <p>
603 * @param level One of the message level identifiers, e.g. SEVERE
604 * @param sourceClass name of class that issued the logging request
605 * @param sourceMethod name of method that issued the logging request
606 * @param bundleName name of resource bundle to localize msg
607 * @param msg The string message (or a key in the message catalog)
608 * @param params Array of parameters to the message
609 * @throws MissingResourceException if no suitable ResourceBundle can
610 * be found.
611 */
612 public void logrb(Level level, String sourceClass, String sourceMethod,
613 String bundleName, String msg, Object params[])
614 {
615 if (isLoggable(level))
616 {
617 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
618 lr.setSourceClassName(sourceClass);
619 lr.setSourceMethodName(sourceMethod);
620 lr.setParameters(params);
621 doLog(lr,bundleName);
622 }
623 }
624
625 /**
626 * Log a message, specifying source class, method, and resource bundle name,
627 * with associated Throwable information.
628 * <p>
629 * If the logger is currently enabled for the given message
630 * level then the given arguments are stored in a LogRecord
631 * which is forwarded to all registered output handlers.
632 * <p>
633 * The msg string is localized using the named resource bundle. If the
634 * resource bundle name is null, then the msg string is not localized.
635 * <p>
636 * Note that the thrown argument is stored in the LogRecord thrown
637 * property, rather than the LogRecord parameters property. Thus is it
638 * processed specially by output Formatters and is not treated
639 * as a formatting parameter to the LogRecord message property.
640 * <p>
641 * @param level One of the message level identifiers, e.g. SEVERE
642 * @param sourceClass name of class that issued the logging request
643 * @param sourceMethod name of method that issued the logging request
644 * @param bundleName name of resource bundle to localize msg
645 * @param msg The string message (or a key in the message catalog)
646 * @param thrown Throwable associated with log message.
647 * @throws MissingResourceException if no suitable ResourceBundle can
648 * be found.
649 */
650 public void logrb(Level level, String sourceClass, String sourceMethod,
651 String bundleName, String msg, Throwable thrown)
652 {
653 if (isLoggable(level))
654 {
655 MyfacesLogRecord lr = new MyfacesLogRecord(level, msg);
656 lr.setSourceClassName(sourceClass);
657 lr.setSourceMethodName(sourceMethod);
658 lr.setThrown(thrown);
659 doLog(lr,bundleName);
660 }
661 }
662
663
664 //======================================================================
665 // Start of convenience methods for logging method entries and returns.
666 //======================================================================
667
668 /**
669 * Log a method entry.
670 * <p>
671 * This is a convenience method that can be used to log entry
672 * to a method. A LogRecord with message "ENTRY", log level
673 * FINER, and the given sourceMethod and sourceClass is logged.
674 * <p>
675 * @param sourceClass name of class that issued the logging request
676 * @param sourceMethod name of method that is being entered
677 */
678 public void entering(String sourceClass, String sourceMethod)
679 {
680 _log.entering(sourceClass, sourceMethod);
681 }
682
683 /**
684 * Log a method entry, with one parameter.
685 * <p>
686 * This is a convenience method that can be used to log entry
687 * to a method. A LogRecord with message "ENTRY {0}", log level
688 * FINER, and the given sourceMethod, sourceClass, and parameter
689 * is logged.
690 * <p>
691 * @param sourceClass name of class that issued the logging request
692 * @param sourceMethod name of method that is being entered
693 * @param param1 parameter to the method being entered
694 */
695 public void entering(String sourceClass, String sourceMethod, Object param1)
696 {
697 _log.entering(sourceClass, sourceMethod, param1);
698 }
699
700 /**
701 * Log a method entry, with an array of parameters.
702 * <p>
703 * This is a convenience method that can be used to log entry
704 * to a method. A LogRecord with message "ENTRY" (followed by a
705 * format {N} indicator for each entry in the parameter array),
706 * log level FINER, and the given sourceMethod, sourceClass, and
707 * parameters is logged.
708 * <p>
709 * @param sourceClass name of class that issued the logging request
710 * @param sourceMethod name of method that is being entered
711 * @param params array of parameters to the method being entered
712 */
713 public void entering(String sourceClass, String sourceMethod, Object params[])
714 {
715 _log.entering(sourceClass, sourceMethod, params);
716 }
717
718 /**
719 * Log a method return.
720 * <p>
721 * This is a convenience method that can be used to log returning
722 * from a method. A LogRecord with message "RETURN", log level
723 * FINER, and the given sourceMethod and sourceClass is logged.
724 * <p>
725 * @param sourceClass name of class that issued the logging request
726 * @param sourceMethod name of the method
727 */
728 public void exiting(String sourceClass, String sourceMethod)
729 {
730 _log.exiting(sourceClass, sourceMethod);
731 }
732
733
734 /**
735 * Log a method return, with result object.
736 * <p>
737 * This is a convenience method that can be used to log returning
738 * from a method. A LogRecord with message "RETURN {0}", log level
739 * FINER, and the gives sourceMethod, sourceClass, and result
740 * object is logged.
741 * <p>
742 * @param sourceClass name of class that issued the logging request
743 * @param sourceMethod name of the method
744 * @param result Object that is being returned
745 */
746 public void exiting(String sourceClass, String sourceMethod, Object result)
747 {
748 _log.exiting(sourceClass, sourceMethod, result);
749 }
750
751 /**
752 * Log throwing an exception.
753 * <p>
754 * This is a convenience method to log that a method is
755 * terminating by throwing an exception. The logging is done
756 * using the FINER level.
757 * <p>
758 * If the logger is currently enabled for the given message
759 * level then the given arguments are stored in a LogRecord
760 * which is forwarded to all registered output handlers. The
761 * LogRecord's message is set to "THROW".
762 * <p>
763 * Note that the thrown argument is stored in the LogRecord thrown
764 * property, rather than the LogRecord parameters property. Thus is it
765 * processed specially by output Formatters and is not treated
766 * as a formatting parameter to the LogRecord message property.
767 * <p>
768 * @param sourceClass name of class that issued the logging request
769 * @param sourceMethod name of the method.
770 * @param thrown The Throwable that is being thrown.
771 */
772 public void throwing(String sourceClass, String sourceMethod, Throwable thrown)
773 {
774 _log.throwing(sourceClass, sourceMethod, thrown);
775 }
776
777 //=======================================================================
778 // Start of simple convenience methods using level names as method names
779 //=======================================================================
780
781 /**
782 * Log a SEVERE message.
783 * <p>
784 * If the logger is currently enabled for the SEVERE message
785 * level then the given message is forwarded to all the
786 * registered output Handler objects.
787 * <p>
788 * @param msg The string message (or a key in the message catalog)
789 */
790 public void severe(String msg)
791 {
792 //_log.severe(msg);
793 log(Level.SEVERE,msg);
794 }
795
796 /**
797 * Log a WARNING message.
798 * <p>
799 * If the logger is currently enabled for the WARNING message
800 * level then the given message is forwarded to all the
801 * registered output Handler objects.
802 * <p>
803 * @param msg The string message (or a key in the message catalog)
804 */
805 public void warning(String msg)
806 {
807 //_log.warning(msg);
808 log(Level.WARNING,msg);
809 }
810
811 /**
812 * Log an INFO message.
813 * <p>
814 * If the logger is currently enabled for the INFO message
815 * level then the given message is forwarded to all the
816 * registered output Handler objects.
817 * <p>
818 * @param msg The string message (or a key in the message catalog)
819 */
820 public void info(String msg)
821 {
822 //_log.info(msg);
823 log(Level.INFO,msg);
824 }
825
826 /**
827 * Log a CONFIG message.
828 * <p>
829 * If the logger is currently enabled for the CONFIG message
830 * level then the given message is forwarded to all the
831 * registered output Handler objects.
832 * <p>
833 * @param msg The string message (or a key in the message catalog)
834 */
835 public void config(String msg)
836 {
837 //_log.config(msg);
838 log(Level.CONFIG,msg);
839 }
840
841 /**
842 * Log a FINE message.
843 * <p>
844 * If the logger is currently enabled for the FINE message
845 * level then the given message is forwarded to all the
846 * registered output Handler objects.
847 * <p>
848 * @param msg The string message (or a key in the message catalog)
849 */
850 public void fine(String msg)
851 {
852 //_log.fine(msg);
853 log(Level.FINE,msg);
854 }
855
856 /**
857 * Log a FINER message.
858 * <p>
859 * If the logger is currently enabled for the FINER message
860 * level then the given message is forwarded to all the
861 * registered output Handler objects.
862 * <p>
863 * @param msg The string message (or a key in the message catalog)
864 */
865 public void finer(String msg)
866 {
867 //_log.finer(msg);
868 log(Level.FINER,msg);
869 }
870
871 /**
872 * Log a FINEST message.
873 * <p>
874 * If the logger is currently enabled for the FINEST message
875 * level then the given message is forwarded to all the
876 * registered output Handler objects.
877 * <p>
878 * @param msg The string message (or a key in the message catalog)
879 */
880 public void finest(String msg)
881 {
882 //_log.finest(msg);
883 log(Level.FINEST,msg);
884 }
885
886 /**
887 * Log throwing an exception.
888 *
889 * Comparing to Java Logging function
890 *
891 * Logger.throwing(sourceClass, sourceMethod, thrown)
892 *
893 * this function takes one more parameter "level" so that developers can
894 * specify the logging level of an exception. Developers should pass value
895 * for the "level" parameter using following convention,
896 * <p>
897 * Level.SEVERE -- Serious exceptions or error conditions such that an
898 * application can no longer run.
899 * <p>
900 * Level.WARNING -- Exceptions or errors that are not fatal, but an
901 * application will run with some problems.
902 * <p>
903 *
904 * @param level Java Logging level
905 * @param sourceClass name of class that issued the logging request
906 * @param sourceMethod name of the method
907 * @param thrown The Throwable that is being thrown
908 */
909 public void throwing(
910 Level level,
911 String sourceClass,
912 String sourceMethod,
913 Throwable thrown
914 )
915 {
916 logp(level, sourceClass, sourceMethod, null, thrown);
917 }
918
919 /**
920 * Log a SEVERE message, with no arguments.
921 * <p>
922 * The message is forwarded to appropriate Java Logger objects.
923 * <p>
924 * @param sourceClass the name of the class that issued the logging request
925 * @param sourceMethod the name of the method that issued the logging request
926 * @param msg the string message (or a key in the resource bundle)
927 */
928 public void severe(
929 String sourceClass,
930 String sourceMethod,
931 String msg
932 )
933 {
934 logp(Level.SEVERE, sourceClass, sourceMethod, msg);
935 }
936
937 /**
938 * Log a SEVERE message, with one object parameter.
939 * <p>
940 * The message is forwarded to appropriate Java Logger objects.
941 * <p>
942 * @param sourceClass the name of the class that issued the logging request
943 * @param sourceMethod the name of the method that issued the logging request
944 * @param msg the string message (or a key in the resource bundle)
945 * @param param1 a parameter to the message
946 */
947 public void severe(
948 String sourceClass,
949 String sourceMethod,
950 String msg,
951 Object param1
952 )
953 {
954 logp(Level.SEVERE, sourceClass, sourceMethod, msg, param1);
955 }
956
957 /**
958 * Log a SEVERE message, with an array of object arguments.
959 * <p>
960 * The message is forwarded to appropriate Java Logger objects.
961 * <p>
962 * @param sourceClass the name of the class that issued the logging request
963 * @param sourceMethod the name of the method that issued the logging request
964 * @param msg the string message (or a key in the resource bundle)
965 * @param params an array of parameters to the message
966 */
967 public void severe(
968 String sourceClass,
969 String sourceMethod,
970 String msg,
971 Object[] params
972 )
973 {
974 logp(Level.SEVERE, sourceClass, sourceMethod, msg, params);
975 }
976
977 /**
978 * Log a WARNING message, with no arguments.
979 * <p>
980 * The message is forwarded to appropriate Java Logger objects.
981 * <p>
982 * @param sourceClass the name of the class that issued the logging request
983 * @param sourceMethod the name of the method that issued the logging request
984 * @param msg the string message (or a key in the resource bundle)
985 */
986 public void warning(
987 String sourceClass,
988 String sourceMethod,
989 String msg
990 )
991 {
992 logp(Level.WARNING, sourceClass, sourceMethod, msg);
993 }
994
995 /**
996 * Log a WARNING message, with one object parameter.
997 * <p>
998 * The message is forwarded to appropriate Java Logger objects.
999 * <p>
1000 * @param sourceClass the name of the class that issued the logging request
1001 * @param sourceMethod the name of the method that issued the logging request
1002 * @param msg the string message (or a key in the resource bundle)
1003 * @param param1 a parameter to the message
1004 */
1005 public void warning(
1006 String sourceClass,
1007 String sourceMethod,
1008 String msg,
1009 Object param1
1010 )
1011 {
1012 logp(Level.WARNING, sourceClass, sourceMethod, msg, param1);
1013 }
1014
1015 /**
1016 * Log a WARNING message, with an array of object arguments.
1017 * <p>
1018 * The message is forwarded to appropriate Java Logger objects.
1019 * <p>
1020 * @param sourceClass the name of the class that issued the logging request
1021 * @param sourceMethod the name of the method that issued the logging request
1022 * @param msg the string message (or a key in the resource bundle)
1023 * @param params an array of parameters to the message
1024 */
1025 public void warning(
1026 String sourceClass,
1027 String sourceMethod,
1028 String msg,
1029 Object[] params
1030 )
1031 {
1032 logp(Level.WARNING, sourceClass, sourceMethod, msg, params);
1033 }
1034
1035 /**
1036 * Log a INFO message, with no arguments.
1037 * <p>
1038 * The message is forwarded to appropriate Java Logger objects.
1039 * <p>
1040 * @param sourceClass the name of the class that issued the logging request
1041 * @param sourceMethod the name of the method that issued the logging request
1042 * @param msg the string message (or a key in the resource bundle)
1043 */
1044 public void info(
1045 String sourceClass,
1046 String sourceMethod,
1047 String msg
1048 )
1049 {
1050 logp(Level.INFO, sourceClass, sourceMethod, msg);
1051 }
1052
1053 /**
1054 * Log a INFO message, with one object parameter.
1055 * <p>
1056 * The message is forwarded to appropriate Java Logger objects.
1057 * <p>
1058 * @param sourceClass the name of the class that issued the logging request
1059 * @param sourceMethod the name of the method that issued the logging request
1060 * @param msg the string message (or a key in the resource bundle)
1061 * @param param1 a parameter to the message
1062 */
1063 public void info(
1064 String sourceClass,
1065 String sourceMethod,
1066 String msg,
1067 Object param1
1068 )
1069 {
1070 logp(Level.INFO, sourceClass, sourceMethod, msg, param1);
1071 }
1072
1073 /**
1074 * Log a INFO message, with an array of object arguments.
1075 * <p>
1076 * The message is forwarded to appropriate Java Logger objects.
1077 * <p>
1078 * @param sourceClass the name of the class that issued the logging request
1079 * @param sourceMethod the name of the method that issued the logging request
1080 * @param msg the string message (or a key in the resource bundle)
1081 * @param params an array of parameters to the message
1082 */
1083 public void info(
1084 String sourceClass,
1085 String sourceMethod,
1086 String msg,
1087 Object[] params
1088 )
1089 {
1090 logp(Level.INFO, sourceClass, sourceMethod, msg, params);
1091 }
1092
1093 /**
1094 * Log a CONFIG message, with no arguments.
1095 * <p>
1096 * The message is forwarded to appropriate Java Logger objects.
1097 * <p>
1098 * @param sourceClass the name of the class that issued the logging request
1099 * @param sourceMethod the name of the method that issued the logging request
1100 * @param msg the string message (or a key in the resource bundle)
1101 */
1102 public void config(
1103 String sourceClass,
1104 String sourceMethod,
1105 String msg
1106 )
1107 {
1108 logp(Level.CONFIG, sourceClass, sourceMethod, msg);
1109 }
1110
1111 /**
1112 * Log a CONFIG message, with one object parameter.
1113 * <p>
1114 * The message is forwarded to appropriate Java Logger objects.
1115 * <p>
1116 * @param sourceClass the name of the class that issued the logging request
1117 * @param sourceMethod the name of the method that issued the logging request
1118 * @param msg the string message (or a key in the resource bundle)
1119 * @param param1 a parameter to the message
1120 */
1121 public void config(
1122 String sourceClass,
1123 String sourceMethod,
1124 String msg,
1125 Object param1
1126 )
1127 {
1128 _log.logp(Level.CONFIG, sourceClass, sourceMethod, msg, param1);
1129 }
1130
1131 /**
1132 * Log a CONFIG message, with an array of object arguments.
1133 * <p>
1134 * The message is forwarded to appropriate Java Logger objects.
1135 * <p>
1136 * @param sourceClass the name of the class that issued the logging request
1137 * @param sourceMethod the name of the method that issued the logging request
1138 * @param msg the string message (or a key in the resource bundle)
1139 * @param params an array of parameters to the message
1140 */
1141 public void config(
1142 String sourceClass,
1143 String sourceMethod,
1144 String msg,
1145 Object[] params
1146 )
1147 {
1148 logp(Level.CONFIG, sourceClass, sourceMethod, msg, params);
1149 }
1150
1151 /**
1152 * Log a FINE message, with no arguments.
1153 * <p>
1154 * The message is forwarded to appropriate Java Logger objects.
1155 * <p>
1156 * @param sourceClass the name of the class that issued the logging request
1157 * @param sourceMethod the name of the method that issued the logging request
1158 * @param msg the string message (or a key in the resource bundle)
1159 */
1160 public void fine(
1161 String sourceClass,
1162 String sourceMethod,
1163 String msg
1164 )
1165 {
1166 logp(Level.FINE, sourceClass, sourceMethod, msg);
1167 }
1168
1169 /**
1170 * Log a FINE message, with one object parameter.
1171 * <p>
1172 * The message is forwarded to appropriate Java Logger objects.
1173 * <p>
1174 * @param sourceClass the name of the class that issued the logging request
1175 * @param sourceMethod the name of the method that issued the logging request
1176 * @param msg the string message (or a key in the resource bundle)
1177 * @param param1 a parameter to the message
1178 */
1179 public void fine(
1180 String sourceClass,
1181 String sourceMethod,
1182 String msg,
1183 Object param1
1184 )
1185 {
1186 logp(Level.FINE, sourceClass, sourceMethod, msg, param1);
1187 }
1188
1189 /**
1190 * Log a FINE message, with an array of object arguments.
1191 * <p>
1192 * The message is forwarded to appropriate Java Logger objects.
1193 * <p>
1194 * @param sourceClass the name of the class that issued the logging request
1195 * @param sourceMethod the name of the method that issued the logging request
1196 * @param msg the string message (or a key in the resource bundle)
1197 * @param params an array of parameters to the message
1198 */
1199 public void fine(
1200 String sourceClass,
1201 String sourceMethod,
1202 String msg,
1203 Object[] params
1204 )
1205 {
1206 logp(Level.FINE, sourceClass, sourceMethod, msg, params);
1207 }
1208
1209 /**
1210 * Log a FINER message, with no arguments.
1211 * <p>
1212 * The message is forwarded to appropriate Java Logger objects.
1213 * <p>
1214 * @param sourceClass the name of the class that issued the logging request
1215 * @param sourceMethod the name of the method that issued the logging request
1216 * @param msg the string message (or a key in the resource bundle)
1217 */
1218 public void finer(
1219 String sourceClass,
1220 String sourceMethod,
1221 String msg
1222 )
1223 {
1224 logp(Level.FINER, sourceClass, sourceMethod, msg);
1225 }
1226
1227 /**
1228 * Log a FINER message, with one object parameter.
1229 * <p>
1230 * The message is forwarded to appropriate Java Logger objects.
1231 * <p>
1232 * @param sourceClass the name of the class that issued the logging request
1233 * @param sourceMethod the name of the method that issued the logging request
1234 * @param msg the string message (or a key in the resource bundle)
1235 * @param param1 a parameter to the message
1236 */
1237 public void finer(
1238 String sourceClass,
1239 String sourceMethod,
1240 String msg,
1241 Object param1
1242 )
1243 {
1244 logp(Level.FINER, sourceClass, sourceMethod, msg, param1);
1245 }
1246
1247 /**
1248 * Log a FINER message, with an array of object arguments.
1249 * <p>
1250 * The message is forwarded to appropriate Java Logger objects.
1251 * <p>
1252 * @param sourceClass the name of the class that issued the logging request
1253 * @param sourceMethod the name of the method that issued the logging request
1254 * @param msg the string message (or a key in the resource bundle)
1255 * @param params an array of parameters to the message
1256 */
1257 public void finer(
1258 String sourceClass,
1259 String sourceMethod,
1260 String msg,
1261 Object[] params
1262 )
1263 {
1264 logp(Level.FINER, sourceClass, sourceMethod, msg, params);
1265 }
1266
1267 /**
1268 * Log a FINEST message, with no arguments.
1269 * <p>
1270 * The message is forwarded to appropriate Java Logger objects.
1271 * <p>
1272 * @param sourceClass the name of the class that issued the logging request
1273 * @param sourceMethod the name of the method that issued the logging request
1274 * @param msg the string message (or a key in the resource bundle)
1275 */
1276 public void finest(
1277 String sourceClass,
1278 String sourceMethod,
1279 String msg
1280 )
1281 {
1282 logp(Level.FINEST, sourceClass, sourceMethod, msg);
1283 }
1284
1285 /**
1286 * Log a FINEST message, with one object parameter.
1287 * <p>
1288 * The message is forwarded to appropriate Java Logger objects.
1289 * <p>
1290 * @param sourceClass the name of the class that issued the logging request
1291 * @param sourceMethod the name of the method that issued the logging request
1292 * @param msg the string message (or a key in the resource bundle)
1293 * @param param1 a parameter to the message
1294 */
1295 public void finest(
1296 String sourceClass,
1297 String sourceMethod,
1298 String msg,
1299 Object param1
1300 )
1301 {
1302 logp(Level.FINEST, sourceClass, sourceMethod, msg, param1);
1303 }
1304
1305 /**
1306 * Log a FINEST message, with an array of object arguments.
1307 * <p>
1308 * The message is forwarded to appropriate Java Logger objects.
1309 * <p>
1310 * @param sourceClass the name of the class that issued the logging request
1311 * @param sourceMethod the name of the method that issued the logging request
1312 * @param msg the string message (or a key in the resource bundle)
1313 * @param params an array of parameters to the message
1314 */
1315 public void finest(
1316 String sourceClass,
1317 String sourceMethod,
1318 String msg,
1319 Object[] params
1320 )
1321 {
1322 logp(Level.FINEST, sourceClass, sourceMethod, msg, params);
1323 }
1324
1325 /**
1326 * Log a message, with an list of object arguments.
1327 * <p>
1328 * The message is forwarded to appropriate Java Logger objects.
1329 * <p>
1330 * @param sourceClass the name of the class that issued the logging request
1331 * @param sourceMethod the name of the method that issued the logging request
1332 * @param msg the string message (or a key in the resource bundle)
1333 * @param params1 Parameter 1 to the log message
1334 * @param params2 Parameter 2 to the log message
1335 * @param params3 Parameter 3 to the log message
1336 */
1337 public void logp(Level level,
1338 String sourceClass,
1339 String sourceMethod,
1340 String msg,
1341 Object params1,
1342 Object params2,
1343 Object params3
1344 )
1345 {
1346 logp(level,sourceClass, sourceMethod, msg, new Object[] {params1, params2, params3});
1347 }
1348
1349 //================================================================
1350 // End of convenience methods
1351 //================================================================
1352
1353 /**
1354 * Set the log level specifying which message levels will be
1355 * logged by this logger. Message levels lower than this
1356 * value will be discarded. The level value Level.OFF
1357 * can be used to turn off logging.
1358 * <p>
1359 * If the new level is null, it means that this node should
1360 * inherit its level from its nearest ancestor with a specific
1361 * (non-null) level value.
1362 *
1363 * @param newLevel the new value for the log level (may be null)
1364 * @exception SecurityException if a security manager exists and if
1365 * the caller does not have LoggingPermission("control").
1366 */
1367 public void setLevel(Level newLevel) throws SecurityException
1368 {
1369 _log.setLevel(newLevel);
1370 }
1371
1372 /**
1373 * Get the log Level that has been specified for this Logger.
1374 * The result may be null, which means that this logger's
1375 * effective level will be inherited from its parent.
1376 *
1377 * @return this Logger's level
1378 */
1379 public Level getLevel()
1380 {
1381 return _log.getLevel();
1382 }
1383
1384 /**
1385 * Check if a message of the given level would actually be logged
1386 * by this logger. This check is based on the Loggers effective level,
1387 * which may be inherited from its parent.
1388 *
1389 * @param level a message logging level
1390 * @return true if the given message level is currently being logged.
1391 */
1392 public boolean isLoggable(Level level)
1393 {
1394 return _log.isLoggable(level);
1395 }
1396
1397 /**
1398 * Get the name for this logger.
1399 * @return logger name. Will be null for anonymous Loggers.
1400 */
1401 public String getName()
1402 {
1403 return _log.getName();
1404 }
1405
1406 /**
1407 * Add a log Handler to receive logging messages.
1408 * <p>
1409 * By default, Loggers also send their output to their parent logger.
1410 * Typically the root Logger is configured with a set of Handlers
1411 * that essentially act as default handlers for all loggers.
1412 *
1413 * @param handler a logging Handler
1414 * @exception SecurityException if a security manager exists and if
1415 * the caller does not have LoggingPermission("control").
1416 */
1417 public void addHandler(Handler handler) throws SecurityException
1418 {
1419 _log.addHandler(handler);
1420 }
1421
1422 /**
1423 * Remove a log Handler.
1424 * <P>
1425 * Returns silently if the given Handler is not found.
1426 *
1427 * @param handler a logging Handler
1428 * @exception SecurityException if a security manager exists and if
1429 * the caller does not have LoggingPermission("control").
1430 */
1431 public void removeHandler(Handler handler) throws SecurityException
1432 {
1433 _log.removeHandler(handler);
1434 }
1435
1436 /**
1437 * Get the Handlers associated with this logger.
1438 * <p>
1439 * @return an array of all registered Handlers
1440 */
1441 public Handler[] getHandlers()
1442 {
1443 return _log.getHandlers();
1444 }
1445
1446 /**
1447 * Specify whether or not this logger should send its output
1448 * to it's parent Logger. This means that any LogRecords will
1449 * also be written to the parent's Handlers, and potentially
1450 * to its parent, recursively up the namespace.
1451 *
1452 * @param useParentHandlers true if output is to be sent to the
1453 * logger's parent.
1454 * @exception SecurityException if a security manager exists and if
1455 * the caller does not have LoggingPermission("control").
1456 */
1457 public void setUseParentHandlers(boolean useParentHandlers)
1458 {
1459 _log.setUseParentHandlers(useParentHandlers);
1460 }
1461
1462 /**
1463 * Discover whether or not this logger is sending its output
1464 * to its parent logger.
1465 *
1466 * @return true if output is to be sent to the logger's parent
1467 */
1468 public boolean getUseParentHandlers()
1469 {
1470 return _log.getUseParentHandlers();
1471 }
1472
1473 /**
1474 * Return the parent for this Logger.
1475 * <p>
1476 * This method returns the nearest extant parent in the namespace.
1477 * Thus if a Logger is called "a.b.c.d", and a Logger called "a.b"
1478 * has been created but no logger "a.b.c" exists, then a call of
1479 * getParent on the Logger "a.b.c.d" will return the Logger "a.b".
1480 * <p>
1481 * The result will be null if it is called on the root Logger
1482 * in the namespace.
1483 *
1484 * @return nearest existing parent Logger
1485 */
1486 public Logger getParent()
1487 {
1488 return _log.getParent();
1489 }
1490
1491 /**
1492 * Set the parent for this Logger. This method is used by
1493 * the LogManager to update a Logger when the namespace changes.
1494 * <p>
1495 * It should not be called from application code.
1496 * <p>
1497 * @param parent the new parent logger
1498 * @exception SecurityException if a security manager exists and if
1499 * the caller does not have LoggingPermission("control").
1500 */
1501 public void setParent(Logger parent)
1502 {
1503 _log.setParent(parent);
1504 }
1505
1506
1507 private ResourceBundle findResourceBundle(String name)
1508 {
1509 // Return a null bundle for a null name.
1510 if (name == null)
1511 {
1512 return null;
1513 }
1514
1515 Locale currentLocale = Locale.getDefault();
1516 return ResourceBundle.getBundle(name, currentLocale);
1517
1518 }
1519
1520
1521 private void doLog(LogRecord lr, String rbname)
1522 {
1523 lr.setLoggerName(_log.getName());
1524 if (rbname != null)
1525 {
1526 lr.setResourceBundleName(rbname);
1527 lr.setResourceBundle(findResourceBundle(rbname));
1528 }
1529 log(lr);
1530 }
1531
1532 private void doLog(LogRecord lr)
1533 {
1534 lr.setLoggerName(_log.getName());
1535 String ebname = _log.getResourceBundleName();
1536 if (ebname != null)
1537 {
1538 lr.setResourceBundleName(ebname);
1539 lr.setResourceBundle(_log.getResourceBundle());
1540 }
1541 _log.log(lr);
1542 }
1543
1544 public void severe(Throwable t)
1545 {
1546 severe(null, t);
1547 }
1548
1549 public void severe(String message, Throwable t)
1550 {
1551 log(Level.SEVERE, message, t);
1552 }
1553
1554 public void severe(String message, Object param)
1555 {
1556 log(Level.SEVERE, message, param);
1557 }
1558
1559 public void severe(String message, Object[] params)
1560 {
1561 log(Level.SEVERE, message, params);
1562 }
1563
1564
1565 public void warning(Throwable t)
1566 {
1567 warning(null, t);
1568 }
1569
1570 public void warning(String message, Throwable t)
1571 {
1572 log(Level.WARNING, message, t);
1573 }
1574
1575 public void warning(String message, Object param)
1576 {
1577 log(Level.WARNING, message, param);
1578 }
1579
1580 public void warning(String message, Object[] params)
1581 {
1582 log(Level.WARNING, message, params);
1583 }
1584
1585 public void info(Throwable t)
1586 {
1587 info(null, t);
1588 }
1589
1590 public void info(String message, Throwable t)
1591 {
1592 log(Level.INFO, message, t);
1593 }
1594
1595 public void info(String message, Object param)
1596 {
1597 log(Level.INFO, message, param);
1598 }
1599
1600 public void info(String message, Object[] params)
1601 {
1602 log(Level.INFO, message, params);
1603 }
1604
1605 public void fine(Throwable t)
1606 {
1607 fine(null, t);
1608 }
1609
1610 public void fine(String message, Throwable t)
1611 {
1612 log(Level.FINE, message, t);
1613 }
1614
1615 public void fine(String message, Object param)
1616 {
1617 log(Level.FINE, message, param);
1618 }
1619
1620 public void fine(String message, Object[] params)
1621 {
1622 log(Level.FINE, message, params);
1623 }
1624
1625 public void finer(Throwable t)
1626 {
1627 finer(null, t);
1628 }
1629
1630 public void finer(String message, Throwable t)
1631 {
1632 log(Level.FINER, message, t);
1633 }
1634
1635 public void finer(String message, Object param)
1636 {
1637 log(Level.FINER, message, param);
1638 }
1639
1640 public void finer(String message, Object[] params)
1641 {
1642 log(Level.FINER, message, params);
1643 }
1644
1645
1646 public void finest(Throwable t)
1647 {
1648 finest(null, t);
1649 }
1650
1651 public void finest(String message, Throwable t)
1652 {
1653 log(Level.FINEST, message, t);
1654 }
1655
1656 public void finest(String message, Object param)
1657 {
1658 log(Level.FINEST, message, param);
1659 }
1660
1661 public void finest(String message, Object[] params)
1662 {
1663 log(Level.FINEST, message, params);
1664 }
1665
1666 /**
1667 * Returns true if severe messages should be logged.
1668 */
1669 public boolean isSevere()
1670 {
1671 return isLoggable(Level.SEVERE);
1672 }
1673
1674 /**
1675 * Returns true if warning messages should be logged.
1676 */
1677 public boolean isWarning()
1678 {
1679 return isLoggable(Level.WARNING);
1680 }
1681
1682
1683 /**
1684 * Returns true if info messages should be logged.
1685 */
1686 public boolean isInfo()
1687 {
1688 return isLoggable(Level.INFO);
1689 }
1690
1691
1692 /**
1693 * Returns true if config messages should be logged.
1694 */
1695 public boolean isConfig()
1696 {
1697 return isLoggable(Level.CONFIG);
1698 }
1699
1700
1701 /**
1702 * Returns true if fine messages should be logged.
1703 */
1704 public boolean isFine()
1705 {
1706 return isLoggable(Level.FINE);
1707 }
1708
1709
1710 /**
1711 * Returns true if finer messages should be logged.
1712 */
1713 public boolean isFiner()
1714 {
1715 return isLoggable(Level.FINER);
1716 }
1717
1718 /**
1719 * Returns true if finest messages should be logged.
1720 */
1721 public boolean isFinest()
1722 {
1723 return isLoggable(Level.FINEST);
1724 }
1725
1726 /**
1727 * Returns message string in default locale
1728 */
1729 public String getMessage(String key)
1730 {
1731 try
1732 {
1733 return _log.getResourceBundle().getString(key);
1734 }
1735 catch (MissingResourceException mre)
1736 {
1737 return key;
1738 }
1739 }
1740
1741 /**
1742 * Returns message string in default locale
1743 */
1744 public String getMessage(MyfacesLogKey key)
1745 {
1746 try
1747 {
1748 String name = key.name();
1749 return _log.getResourceBundle().getString(name);
1750 }
1751 catch (MissingResourceException mre)
1752 {
1753 return key.name();
1754 }
1755 }
1756
1757 /**
1758 * Returns message string in default locale
1759 */
1760 public MyfacesLogMessage getMyfacesMessage(MyfacesLogKey key)
1761 {
1762 MyfacesLogMessage facesMessage = new MyfacesLogMessage();
1763 try
1764 {
1765
1766 String name = key.name();
1767 String summary = _log.getResourceBundle().getString(name);
1768 facesMessage.setSummary(summary);
1769 try
1770 {
1771 String detail = _log.getResourceBundle().getString(name +"_detail");
1772 facesMessage.setDetail(detail);
1773 } catch (MissingResourceException e) {
1774 facesMessage.setDetail(name);
1775 }
1776
1777 try
1778 {
1779 String related = _log.getResourceBundle().getString(name +"_related");
1780 facesMessage.setRelated(related);
1781 } catch (MissingResourceException e) {
1782 /// ignore
1783 }
1784 return facesMessage;
1785 }
1786 catch (MissingResourceException mre)
1787 {
1788 facesMessage.setSummary(key.name());
1789 return facesMessage;
1790 }
1791 }
1792
1793 /**
1794 * Returns formated string in default locale
1795 */
1796 public String getMessage(String key, Object... params)
1797 {
1798 String message = getMessage(key);
1799 MessageFormat fmt = new MessageFormat(message);
1800 return fmt.format(params);
1801 }
1802
1803 /**
1804 * Returns formated string in default locale
1805 */
1806 public String getMessage(String key, Object param)
1807 {
1808 return getMessage(key, new Object[]{param});
1809 }
1810
1811 private Logger _log;
1812
1813 /** Currenly this logger is used only in myfaces-impl: therefore LoggerBundle is same for both api and impl*/
1814 private static final String _API_LOGGER_BUNDLE = "org.apache.myfaces.resource.LoggerBundle";
1815
1816 private static final String _IMPL_LOGGER_BUNDLE = "org.apache.myfaces.resource.LoggerBundle";
1817
1818 private static final MyfacesLogger _LOG = MyfacesLogger.createMyfacesLogger(
1819 MyfacesLogger.class);
1820 }