1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j;
18
19 import org.apache.log4j.spi.LoggingEvent;
20
21 import java.text.DateFormat;
22 import java.text.MessageFormat;
23 import java.text.NumberFormat;
24 import java.util.Date;
25 import java.util.ResourceBundle;
26
27
28 /***
29 * This class provides static methods to
30 * format log messages using java.text.MessageFormat.
31 *
32 */
33 public final class LogMF {
34 /***
35 * Trace level.
36 */
37 private static final Level TRACE = new Level(5000, "TRACE", 7);
38 /***
39 * private constructor.
40 *
41 */
42 private LogMF() {
43 }
44
45
46 /***
47 * Returns a Boolean instance representing the specified boolean.
48 * Boolean.valueOf was added in JDK 1.4.
49 * @param b a boolean value.
50 * @return a Boolean instance representing b.
51 */
52 private static Boolean valueOf(final boolean b) {
53 if (b) {
54 return Boolean.TRUE;
55 }
56 return Boolean.FALSE;
57 }
58
59 /***
60 * Returns a Character instance representing the specified char.
61 * Character.valueOf was added in JDK 1.5.
62 * @param c a character value.
63 * @return a Character instance representing c.
64 */
65 private static Character valueOf(final char c) {
66 return new Character(c);
67 }
68
69 /***
70 * Returns a Byte instance representing the specified byte.
71 * Byte.valueOf was added in JDK 1.5.
72 * @param b a byte value.
73 * @return a Byte instance representing b.
74 */
75 private static Byte valueOf(final byte b) {
76 return new Byte(b);
77 }
78
79 /***
80 * Returns a Short instance representing the specified short.
81 * Short.valueOf was added in JDK 1.5.
82 * @param b a short value.
83 * @return a Byte instance representing b.
84 */
85 private static Short valueOf(final short b) {
86 return new Short(b);
87 }
88
89 /***
90 * Returns an Integer instance representing the specified int.
91 * Integer.valueOf was added in JDK 1.5.
92 * @param b an int value.
93 * @return an Integer instance representing b.
94 */
95 private static Integer valueOf(final int b) {
96 return new Integer(b);
97 }
98
99 /***
100 * Returns a Long instance representing the specified long.
101 * Long.valueOf was added in JDK 1.5.
102 * @param b a long value.
103 * @return a Long instance representing b.
104 */
105 private static Long valueOf(final long b) {
106 return new Long(b);
107 }
108
109 /***
110 * Returns a Float instance representing the specified float.
111 * Float.valueOf was added in JDK 1.5.
112 * @param b a float value.
113 * @return a Float instance representing b.
114 */
115 private static Float valueOf(final float b) {
116 return new Float(b);
117 }
118
119 /***
120 * Returns a Double instance representing the specified double.
121 * Double.valueOf was added in JDK 1.5.
122 * @param b a double value.
123 * @return a Byte instance representing b.
124 */
125 private static Double valueOf(final double b) {
126 return new Double(b);
127 }
128
129
130
131 /***
132 * Create new array.
133 * @param param1 parameter 1.
134 * @return new array.
135 */
136 private static Object[] toArray(final Object param1) {
137 return new Object[] {
138 param1
139 };
140 }
141
142 /***
143 * Create new array.
144 * @param param1 parameter 1.
145 * @param param2 parameter 2.
146 * @return new array.
147 */
148 private static Object[] toArray(final Object param1,
149 final Object param2) {
150 return new Object[] {
151 param1, param2
152 };
153 }
154
155 /***
156 * Create new array.
157 * @param param1 parameter 1.
158 * @param param2 parameter 2.
159 * @param param3 parameter 3.
160 * @return new array.
161 */
162 private static Object[] toArray(final Object param1,
163 final Object param2,
164 final Object param3) {
165 return new Object[] {
166 param1, param2, param3
167 };
168 }
169
170 /***
171 * Create new array.
172 * @param param1 parameter 1.
173 * @param param2 parameter 2.
174 * @param param3 parameter 3.
175 * @param param4 parameter 4.
176 * @return new array.
177 */
178 private static Object[] toArray(final Object param1,
179 final Object param2,
180 final Object param3,
181 final Object param4) {
182 return new Object[] {
183 param1, param2, param3, param4
184 };
185 }
186
187 /***
188 * Formats arguments using a minimal subset
189 * of MessageFormat syntax.
190 * @param pattern pattern, may not be null.
191 * @param arg0 argument, may be null.
192 * @return Message string or null if pattern
193 * is not supported.
194 */
195 private static String subsetFormat(final String pattern,
196 final Object arg0) {
197 if (pattern != null) {
198
199
200
201 int bracePos = pattern.indexOf("{");
202
203
204
205
206
207 if (bracePos != -1) {
208 if ((pattern.indexOf("{0}", bracePos) == bracePos)
209 && (pattern.indexOf("{", bracePos + 1) == -1)
210 && (pattern.indexOf("'") == -1)) {
211 String replacement;
212
213 if (arg0 instanceof String) {
214 replacement = arg0.toString();
215 } else if (arg0 instanceof Number) {
216 replacement = NumberFormat.getInstance().format(arg0);
217 } else if (arg0 instanceof Date) {
218 replacement = DateFormat.getDateTimeInstance(
219 DateFormat.SHORT,
220 DateFormat.SHORT).format(arg0);
221 } else {
222 replacement = String.valueOf(arg0);
223 }
224
225 final StringBuffer buf = new StringBuffer(pattern);
226 buf.replace(bracePos,
227 bracePos + "{0}".length(), replacement);
228
229 return buf.toString();
230 }
231 } else {
232
233
234
235 if (pattern.indexOf("'") == -1) {
236 return pattern;
237 }
238 }
239 }
240
241 return null;
242 }
243
244 /***
245 * Formats arguments using MessageFormat.
246 * @param pattern pattern, may be malformed or null.
247 * @param arguments arguments, may be null or mismatched.
248 * @return Message string or null
249 */
250 private static String format(final String pattern,
251 final Object[] arguments) {
252 if (pattern == null) {
253 return null;
254 }
255 try {
256 return MessageFormat.format(pattern, arguments);
257 } catch (IllegalArgumentException ex) {
258 return pattern;
259 }
260 }
261
262 /***
263 * Formats arguments using MessageFormat.
264 * @param pattern pattern, may be malformed.
265 * @param arg0 argument, may be null or mismatched.
266 * @return Message string
267 */
268 private static String format(final String pattern, final Object arg0) {
269 String msg = subsetFormat(pattern, arg0);
270
271 if (msg == null) {
272 msg = format(pattern, toArray(arg0));
273 }
274
275 return msg;
276 }
277
278 /***
279 * Formats arguments using MessageFormat using a pattern from
280 * a resource bundle.
281 * @param resourceBundleName name of resource bundle, may be null.
282 * @param key key for pattern in resource bundle, may be null.
283 * @param arguments arguments, may be null or mismatched.
284 * @return Message string or null
285 */
286 private static String format(
287 final String resourceBundleName,
288 final String key,
289 final Object[] arguments) {
290 String pattern;
291 if (resourceBundleName != null) {
292 try {
293 ResourceBundle bundle =
294 ResourceBundle.getBundle(resourceBundleName);
295 pattern = bundle.getString(key);
296 } catch (Exception ex) {
297 pattern = key;
298 }
299 } else {
300 pattern = key;
301 }
302 return format(pattern, arguments);
303 }
304
305
306 /***
307 * Fully Qualified Class Name of this class.
308 */
309 private static final String FQCN = LogMF.class.getName();
310
311 /***
312 * Equivalent of Logger.forcedLog.
313 *
314 * @param logger logger, may not be null.
315 * @param level level, may not be null.
316 * @param msg message, may be null.
317 */
318 private static void forcedLog(final Logger logger,
319 final Level level,
320 final String msg) {
321 logger.callAppenders(new LoggingEvent(FQCN, logger, level, msg, null));
322 }
323
324 /***
325 * Equivalent of Logger.forcedLog.
326 *
327 * @param logger logger, may not be null.
328 * @param level level, may not be null.
329 * @param msg message, may be null.
330 * @param t throwable.
331 */
332 private static void forcedLog(final Logger logger,
333 final Level level,
334 final String msg,
335 final Throwable t) {
336 logger.callAppenders(new LoggingEvent(FQCN, logger, level, msg, t));
337 }
338 /***
339 * Log a parameterized message at trace level.
340 * @param logger logger, may not be null.
341 * @param pattern pattern, may be null.
342 * @param arguments an array of arguments to be
343 * formatted and substituted.
344 */
345 public static void trace(final Logger logger, final String pattern,
346 final Object[] arguments) {
347 if (logger.isEnabledFor(TRACE)) {
348 forcedLog(logger, TRACE, format(pattern, arguments));
349 }
350 }
351
352 /***
353 * Log a parameterized message at debug level.
354 * @param logger logger, may not be null.
355 * @param pattern pattern, may be null.
356 * @param arguments an array of arguments to be formatted and substituted.
357 */
358 public static void debug(final Logger logger, final String pattern,
359 final Object[] arguments) {
360 if (logger.isDebugEnabled()) {
361 forcedLog(logger, Level.DEBUG, format(pattern, arguments));
362 }
363 }
364
365 /***
366 * Log a parameterized message at info level.
367 * @param logger logger, may not be null.
368 * @param pattern pattern, may be null.
369 * @param arguments an array of arguments to be formatted and substituted.
370 */
371 public static void info(final Logger logger, final String pattern,
372 final Object[] arguments) {
373 if (logger.isInfoEnabled()) {
374 forcedLog(logger, Level.INFO, format(pattern, arguments));
375 }
376 }
377
378 /***
379 * Log a parameterized message at warn level.
380 * @param logger logger, may not be null.
381 * @param pattern pattern, may be null.
382 * @param arguments an array of arguments to be formatted and substituted.
383 */
384 public static void warn(final Logger logger, final String pattern,
385 final Object[] arguments) {
386 if (logger.isEnabledFor(Level.WARN)) {
387 forcedLog(logger, Level.WARN, format(pattern, arguments));
388 }
389 }
390
391 /***
392 * Log a parameterized message at error level.
393 * @param logger logger, may not be null.
394 * @param pattern pattern, may be null.
395 * @param arguments an array of arguments to be formatted and substituted.
396 */
397 public static void error(final Logger logger, final String pattern,
398 final Object[] arguments) {
399 if (logger.isEnabledFor(Level.ERROR)) {
400 forcedLog(logger, Level.ERROR, format(pattern, arguments));
401 }
402 }
403
404 /***
405 * Log a parameterized message at fatal level.
406 * @param logger logger, may not be null.
407 * @param pattern pattern, may be null.
408 * @param arguments an array of arguments to be formatted and substituted.
409 */
410 public static void fatal(final Logger logger, final String pattern,
411 final Object[] arguments) {
412 if (logger.isEnabledFor(Level.FATAL)) {
413 forcedLog(logger, Level.FATAL, format(pattern, arguments));
414 }
415 }
416
417 /***
418 * Log a parameterized message at trace level.
419 * @param logger logger, may not be null.
420 * @param t throwable, may be null.
421 * @param pattern pattern, may be null.
422 * @param arguments an array of arguments to be
423 * formatted and substituted.
424 */
425 public static void trace(final Logger logger,
426 final Throwable t,
427 final String pattern,
428 final Object[] arguments) {
429 if (logger.isEnabledFor(TRACE)) {
430 forcedLog(logger, TRACE, format(pattern, arguments), t);
431 }
432 }
433
434 /***
435 * Log a parameterized message at debug level.
436 * @param logger logger, may not be null.
437 * @param t throwable, may be null.
438 * @param pattern pattern, may be null.
439 * @param arguments an array of arguments to be formatted and substituted.
440 */
441 public static void debug(final Logger logger,
442 final Throwable t,
443 final String pattern,
444 final Object[] arguments) {
445 if (logger.isDebugEnabled()) {
446 forcedLog(logger, Level.DEBUG, format(pattern, arguments), t);
447 }
448 }
449
450 /***
451 * Log a parameterized message at info level.
452 * @param logger logger, may not be null.
453 * @param t throwable, may be null.
454 * @param pattern pattern, may be null.
455 * @param arguments an array of arguments to be formatted and substituted.
456 */
457 public static void info(final Logger logger,
458 final Throwable t,
459 final String pattern,
460 final Object[] arguments) {
461 if (logger.isInfoEnabled()) {
462 forcedLog(logger, Level.INFO, format(pattern, arguments), t);
463 }
464 }
465
466 /***
467 * Log a parameterized message at warn level.
468 * @param logger logger, may not be null.
469 * @param t throwable, may be null.
470 * @param pattern pattern, may be null.
471 * @param arguments an array of arguments to be formatted and substituted.
472 */
473 public static void warn(final Logger logger,
474 final Throwable t,
475 final String pattern,
476 final Object[] arguments) {
477 if (logger.isEnabledFor(Level.WARN)) {
478 forcedLog(logger, Level.WARN, format(pattern, arguments), t);
479 }
480 }
481
482 /***
483 * Log a parameterized message at error level.
484 * @param logger logger, may not be null.
485 * @param t throwable, may be null.
486 * @param pattern pattern, may be null.
487 * @param arguments an array of arguments to be formatted and substituted.
488 */
489 public static void error(final Logger logger,
490 final Throwable t,
491 final String pattern,
492 final Object[] arguments) {
493 if (logger.isEnabledFor(Level.ERROR)) {
494 forcedLog(logger, Level.ERROR, format(pattern, arguments), t);
495 }
496 }
497
498 /***
499 * Log a parameterized message at fatal level.
500 * @param logger logger, may not be null.
501 * @param t throwable, may be null.
502 * @param pattern pattern, may be null.
503 * @param arguments an array of arguments to be formatted and substituted.
504 */
505 public static void fatal(final Logger logger,
506 final Throwable t,
507 final String pattern,
508 final Object[] arguments) {
509 if (logger.isEnabledFor(Level.FATAL)) {
510 forcedLog(logger, Level.FATAL, format(pattern, arguments), t);
511 }
512 }
513
514
515
516 /***
517 * Log a parameterized message at trace level.
518 * @param logger logger, may not be null.
519 * @param pattern pattern, may be null.
520 * @param argument a value to be formatted and substituted.
521 */
522 public static void trace(final Logger logger, final String pattern,
523 final boolean argument) {
524 if (logger.isEnabledFor(TRACE)) {
525 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
526 }
527 }
528
529 /***
530 * Log a parameterized message at trace level.
531 * @param logger logger, may not be null.
532 * @param pattern pattern, may be null.
533 * @param argument a value to be formatted and substituted.
534 */
535 public static void trace(final Logger logger, final String pattern,
536 final char argument) {
537 if (logger.isEnabledFor(TRACE)) {
538 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
539 }
540 }
541
542 /***
543 * Log a parameterized message at trace level.
544 * @param logger logger, may not be null.
545 * @param pattern pattern, may be null.
546 * @param argument a value to be formatted and substituted.
547 */
548 public static void trace(final Logger logger, final String pattern,
549 final byte argument) {
550 if (logger.isEnabledFor(TRACE)) {
551 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
552 }
553 }
554
555 /***
556 * Log a parameterized message at trace level.
557 * @param logger logger, may not be null.
558 * @param pattern pattern, may be null.
559 * @param argument a value to be formatted and substituted.
560 */
561 public static void trace(final Logger logger, final String pattern,
562 final short argument) {
563 if (logger.isEnabledFor(TRACE)) {
564 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
565 }
566 }
567
568 /***
569 * Log a parameterized message at trace level.
570 * @param logger logger, may not be null.
571 * @param pattern pattern, may be null.
572 * @param argument a value to be formatted and substituted.
573 */
574 public static void trace(final Logger logger, final String pattern,
575 final int argument) {
576 if (logger.isEnabledFor(TRACE)) {
577 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
578 }
579 }
580
581 /***
582 * Log a parameterized message at trace level.
583 * @param logger logger, may not be null.
584 * @param pattern pattern, may be null.
585 * @param argument a value to be formatted and substituted.
586 */
587 public static void trace(final Logger logger, final String pattern,
588 final long argument) {
589 if (logger.isEnabledFor(TRACE)) {
590 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
591 }
592 }
593
594 /***
595 * Log a parameterized message at trace level.
596 * @param logger logger, may not be null.
597 * @param pattern pattern, may be null.
598 * @param argument a value to be formatted and substituted.
599 */
600 public static void trace(final Logger logger, final String pattern,
601 final float argument) {
602 if (logger.isEnabledFor(TRACE)) {
603 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
604 }
605 }
606
607 /***
608 * Log a parameterized message at trace level.
609 * @param logger logger, may not be null.
610 * @param pattern pattern, may be null.
611 * @param argument a value to be formatted and substituted.
612 */
613 public static void trace(final Logger logger, final String pattern,
614 final double argument) {
615 if (logger.isEnabledFor(TRACE)) {
616 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
617 }
618 }
619
620 /***
621 * Log a parameterized message at trace level.
622 * @param logger logger, may not be null.
623 * @param pattern pattern, may be null.
624 * @param argument a value to be formatted and substituted.
625 */
626 public static void trace(final Logger logger, final String pattern,
627 final Object argument) {
628 if (logger.isEnabledFor(TRACE)) {
629 forcedLog(logger, TRACE, format(pattern, argument));
630 }
631 }
632
633 /***
634 * Log a parameterized message at trace level.
635 * @param logger logger, may not be null.
636 * @param pattern pattern, may be null.
637 * @param arg0 a value to be formatted and substituted.
638 * @param arg1 a value to be formatted and substituted.
639 */
640 public static void trace(final Logger logger, final String pattern,
641 final Object arg0, final Object arg1) {
642 if (logger.isEnabledFor(TRACE)) {
643 forcedLog(logger, TRACE,
644 format(pattern, toArray(arg0, arg1)));
645 }
646 }
647
648 /***
649 * Log a parameterized message at trace level.
650 * @param logger logger, may not be null.
651 * @param pattern pattern, may be null.
652 * @param arg0 a value to be formatted and substituted.
653 * @param arg1 a value to be formatted and substituted.
654 * @param arg2 a value to be formatted and substituted.
655 */
656 public static void trace(final Logger logger, final String pattern,
657 final Object arg0, final Object arg1, final Object arg2) {
658 if (logger.isEnabledFor(TRACE)) {
659 forcedLog(logger, TRACE,
660 format(pattern, toArray(arg0, arg1, arg2)));
661 }
662 }
663
664 /***
665 * Log a parameterized message at trace level.
666 * @param logger logger, may not be null.
667 * @param pattern pattern, may be null.
668 * @param arg0 a value to be formatted and substituted.
669 * @param arg1 a value to be formatted and substituted.
670 * @param arg2 a value to be formatted and substituted.
671 * @param arg3 a value to be formatted and substituted.
672 */
673 public static void trace(final Logger logger, final String pattern,
674 final Object arg0, final Object arg1, final Object arg2,
675 final Object arg3) {
676 if (logger.isEnabledFor(TRACE)) {
677 forcedLog(logger, TRACE,
678 format(pattern, toArray(arg0, arg1, arg2, arg3)));
679 }
680 }
681
682 /***
683 * Log a parameterized message at debug level.
684 * @param logger logger, may not be null.
685 * @param pattern pattern, may be null.
686 * @param argument a value to be formatted and substituted.
687 */
688 public static void debug(final Logger logger, final String pattern,
689 final boolean argument) {
690 if (logger.isDebugEnabled()) {
691 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
692 }
693 }
694
695 /***
696 * Log a parameterized message at debug level.
697 * @param logger logger, may not be null.
698 * @param pattern pattern, may be null.
699 * @param argument a value to be formatted and substituted.
700 */
701 public static void debug(final Logger logger, final String pattern,
702 final char argument) {
703 if (logger.isDebugEnabled()) {
704 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
705 }
706 }
707
708 /***
709 * Log a parameterized message at debug level.
710 * @param logger logger, may not be null.
711 * @param pattern pattern, may be null.
712 * @param argument a value to be formatted and substituted.
713 */
714 public static void debug(final Logger logger, final String pattern,
715 final byte argument) {
716 if (logger.isDebugEnabled()) {
717 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
718 }
719 }
720
721 /***
722 * Log a parameterized message at debug level.
723 * @param logger logger, may not be null.
724 * @param pattern pattern, may be null.
725 * @param argument a value to be formatted and substituted.
726 */
727 public static void debug(final Logger logger, final String pattern,
728 final short argument) {
729 if (logger.isDebugEnabled()) {
730 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
731 }
732 }
733
734 /***
735 * Log a parameterized message at debug level.
736 * @param logger logger, may not be null.
737 * @param pattern pattern, may be null.
738 * @param argument a value to be formatted and substituted.
739 */
740 public static void debug(final Logger logger, final String pattern,
741 final int argument) {
742 if (logger.isDebugEnabled()) {
743 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
744 }
745 }
746
747 /***
748 * Log a parameterized message at debug level.
749 * @param logger logger, may not be null.
750 * @param pattern pattern, may be null.
751 * @param argument a value to be formatted and substituted.
752 */
753 public static void debug(final Logger logger, final String pattern,
754 final long argument) {
755 if (logger.isDebugEnabled()) {
756 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
757 }
758 }
759
760 /***
761 * Log a parameterized message at debug level.
762 * @param logger logger, may not be null.
763 * @param pattern pattern, may be null.
764 * @param argument a value to be formatted and substituted.
765 */
766 public static void debug(final Logger logger, final String pattern,
767 final float argument) {
768 if (logger.isDebugEnabled()) {
769 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
770 }
771 }
772
773 /***
774 * Log a parameterized message at debug level.
775 * @param logger logger, may not be null.
776 * @param pattern pattern, may be null.
777 * @param argument a value to be formatted and substituted.
778 */
779 public static void debug(final Logger logger, final String pattern,
780 final double argument) {
781 if (logger.isDebugEnabled()) {
782 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
783 }
784 }
785
786 /***
787 * Log a parameterized message at debug level.
788 * @param logger logger, may not be null.
789 * @param pattern pattern, may be null.
790 * @param argument a value to be formatted and substituted.
791 */
792 public static void debug(final Logger logger, final String pattern,
793 final Object argument) {
794 if (logger.isDebugEnabled()) {
795 forcedLog(logger, Level.DEBUG, format(pattern, argument));
796 }
797 }
798
799 /***
800 * Log a parameterized message at debug level.
801 * @param logger logger, may not be null.
802 * @param pattern pattern, may be null.
803 * @param arg0 a value to be formatted and substituted.
804 * @param arg1 a value to be formatted and substituted.
805 */
806 public static void debug(final Logger logger, final String pattern,
807 final Object arg0, final Object arg1) {
808 if (logger.isDebugEnabled()) {
809 forcedLog(logger, Level.DEBUG,
810 format(pattern, toArray(arg0, arg1)));
811 }
812 }
813
814 /***
815 * Log a parameterized message at debug level.
816 * @param logger logger, may not be null.
817 * @param pattern pattern, may be null.
818 * @param arg0 a value to be formatted and substituted.
819 * @param arg1 a value to be formatted and substituted.
820 * @param arg2 a value to be formatted and substituted.
821 */
822 public static void debug(final Logger logger, final String pattern,
823 final Object arg0, final Object arg1, final Object arg2) {
824 if (logger.isDebugEnabled()) {
825 forcedLog(logger, Level.DEBUG,
826 format(pattern, toArray(arg0, arg1, arg2)));
827 }
828 }
829
830 /***
831 * Log a parameterized message at debug level.
832 * @param logger logger, may not be null.
833 * @param pattern pattern, may be null.
834 * @param arg0 a value to be formatted and substituted.
835 * @param arg1 a value to be formatted and substituted.
836 * @param arg2 a value to be formatted and substituted.
837 * @param arg3 a value to be formatted and substituted.
838 */
839 public static void debug(final Logger logger, final String pattern,
840 final Object arg0, final Object arg1, final Object arg2,
841 final Object arg3) {
842 if (logger.isDebugEnabled()) {
843 forcedLog(logger, Level.DEBUG,
844 format(pattern, toArray(arg0, arg1, arg2, arg3)));
845 }
846 }
847
848 /***
849 * Log a parameterized message at info level.
850 * @param logger logger, may not be null.
851 * @param pattern pattern, may be null.
852 * @param argument a value to be formatted and substituted.
853 */
854 public static void info(final Logger logger, final String pattern,
855 final boolean argument) {
856 if (logger.isInfoEnabled()) {
857 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
858 }
859 }
860
861 /***
862 * Log a parameterized message at info level.
863 * @param logger logger, may not be null.
864 * @param pattern pattern, may be null.
865 * @param argument a value to be formatted and substituted.
866 */
867 public static void info(final Logger logger, final String pattern,
868 final char argument) {
869 if (logger.isInfoEnabled()) {
870 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
871 }
872 }
873
874 /***
875 * Log a parameterized message at info level.
876 * @param logger logger, may not be null.
877 * @param pattern pattern, may be null.
878 * @param argument a value to be formatted and substituted.
879 */
880 public static void info(final Logger logger, final String pattern,
881 final byte argument) {
882 if (logger.isInfoEnabled()) {
883 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
884 }
885 }
886
887 /***
888 * Log a parameterized message at info level.
889 * @param logger logger, may not be null.
890 * @param pattern pattern, may be null.
891 * @param argument a value to be formatted and substituted.
892 */
893 public static void info(final Logger logger, final String pattern,
894 final short argument) {
895 if (logger.isInfoEnabled()) {
896 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
897 }
898 }
899
900 /***
901 * Log a parameterized message at info level.
902 * @param logger logger, may not be null.
903 * @param pattern pattern, may be null.
904 * @param argument a value to be formatted and substituted.
905 */
906 public static void info(final Logger logger, final String pattern,
907 final int argument) {
908 if (logger.isInfoEnabled()) {
909 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
910 }
911 }
912
913 /***
914 * Log a parameterized message at info level.
915 * @param logger logger, may not be null.
916 * @param pattern pattern, may be null.
917 * @param argument a value to be formatted and substituted.
918 */
919 public static void info(final Logger logger, final String pattern,
920 final long argument) {
921 if (logger.isInfoEnabled()) {
922 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
923 }
924 }
925
926 /***
927 * Log a parameterized message at info level.
928 * @param logger logger, may not be null.
929 * @param pattern pattern, may be null.
930 * @param argument a value to be formatted and substituted.
931 */
932 public static void info(final Logger logger, final String pattern,
933 final float argument) {
934 if (logger.isInfoEnabled()) {
935 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
936 }
937 }
938
939 /***
940 * Log a parameterized message at info level.
941 * @param logger logger, may not be null.
942 * @param pattern pattern, may be null.
943 * @param argument a value to be formatted and substituted.
944 */
945 public static void info(final Logger logger, final String pattern,
946 final double argument) {
947 if (logger.isInfoEnabled()) {
948 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
949 }
950 }
951
952 /***
953 * Log a parameterized message at info level.
954 * @param logger logger, may not be null.
955 * @param pattern pattern, may be null.
956 * @param argument a value to be formatted and substituted.
957 */
958 public static void info(final Logger logger, final String pattern,
959 final Object argument) {
960 if (logger.isInfoEnabled()) {
961 forcedLog(logger, Level.INFO, format(pattern, argument));
962 }
963 }
964
965 /***
966 * Log a parameterized message at info level.
967 * @param logger logger, may not be null.
968 * @param pattern pattern, may be null.
969 * @param arg0 a value to be formatted and substituted.
970 * @param arg1 a value to be formatted and substituted.
971 */
972 public static void info(final Logger logger, final String pattern,
973 final Object arg0, final Object arg1) {
974 if (logger.isInfoEnabled()) {
975 forcedLog(logger, Level.INFO, format(pattern, toArray(arg0, arg1)));
976 }
977 }
978
979 /***
980 * Log a parameterized message at info level.
981 * @param logger logger, may not be null.
982 * @param pattern pattern, may be null.
983 * @param arg0 a value to be formatted and substituted.
984 * @param arg1 a value to be formatted and substituted.
985 * @param arg2 a value to be formatted and substituted.
986 */
987 public static void info(final Logger logger, final String pattern,
988 final Object arg0, final Object arg1, final Object arg2) {
989 if (logger.isInfoEnabled()) {
990 forcedLog(logger, Level.INFO, format(pattern,
991 toArray(arg0, arg1, arg2)));
992 }
993 }
994
995 /***
996 * Log a parameterized message at info level.
997 * @param logger logger, may not be null.
998 * @param pattern pattern, may be null.
999 * @param arg0 a value to be formatted and substituted.
1000 * @param arg1 a value to be formatted and substituted.
1001 * @param arg2 a value to be formatted and substituted.
1002 * @param arg3 a value to be formatted and substituted.
1003 */
1004 public static void info(final Logger logger, final String pattern,
1005 final Object arg0, final Object arg1, final Object arg2,
1006 final Object arg3) {
1007 if (logger.isInfoEnabled()) {
1008 forcedLog(logger, Level.INFO, format(pattern,
1009 toArray(arg0, arg1, arg2, arg3)));
1010 }
1011 }
1012
1013 /***
1014 * Log a parameterized message at warn level.
1015 * @param logger logger, may not be null.
1016 * @param pattern pattern, may be null.
1017 * @param argument a value to be formatted and substituted.
1018 */
1019 public static void warn(final Logger logger, final String pattern,
1020 final boolean argument) {
1021 if (logger.isEnabledFor(Level.WARN)) {
1022 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1023 }
1024 }
1025
1026 /***
1027 * Log a parameterized message at warn level.
1028 * @param logger logger, may not be null.
1029 * @param pattern pattern, may be null.
1030 * @param argument a value to be formatted and substituted.
1031 */
1032 public static void warn(final Logger logger, final String pattern,
1033 final char argument) {
1034 if (logger.isEnabledFor(Level.WARN)) {
1035 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1036 }
1037 }
1038
1039 /***
1040 * Log a parameterized message at warn level.
1041 * @param logger logger, may not be null.
1042 * @param pattern pattern, may be null.
1043 * @param argument a value to be formatted and substituted.
1044 */
1045 public static void warn(final Logger logger, final String pattern,
1046 final byte argument) {
1047 if (logger.isEnabledFor(Level.WARN)) {
1048 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1049 }
1050 }
1051
1052 /***
1053 * Log a parameterized message at warn level.
1054 * @param logger logger, may not be null.
1055 * @param pattern pattern, may be null.
1056 * @param argument a value to be formatted and substituted.
1057 */
1058 public static void warn(final Logger logger, final String pattern,
1059 final short argument) {
1060 if (logger.isEnabledFor(Level.WARN)) {
1061 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1062 }
1063 }
1064
1065 /***
1066 * Log a parameterized message at warn level.
1067 * @param logger logger, may not be null.
1068 * @param pattern pattern, may be null.
1069 * @param argument a value to be formatted and substituted.
1070 */
1071 public static void warn(final Logger logger, final String pattern,
1072 final int argument) {
1073 if (logger.isEnabledFor(Level.WARN)) {
1074 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1075 }
1076 }
1077
1078 /***
1079 * Log a parameterized message at warn level.
1080 * @param logger logger, may not be null.
1081 * @param pattern pattern, may be null.
1082 * @param argument a value to be formatted and substituted.
1083 */
1084 public static void warn(final Logger logger, final String pattern,
1085 final long argument) {
1086 if (logger.isEnabledFor(Level.WARN)) {
1087 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1088 }
1089 }
1090
1091 /***
1092 * Log a parameterized message at warn level.
1093 * @param logger logger, may not be null.
1094 * @param pattern pattern, may be null.
1095 * @param argument a value to be formatted and substituted.
1096 */
1097 public static void warn(final Logger logger, final String pattern,
1098 final float argument) {
1099 if (logger.isEnabledFor(Level.WARN)) {
1100 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1101 }
1102 }
1103
1104 /***
1105 * Log a parameterized message at warn level.
1106 * @param logger logger, may not be null.
1107 * @param pattern pattern, may be null.
1108 * @param argument a value to be formatted and substituted.
1109 */
1110 public static void warn(final Logger logger, final String pattern,
1111 final double argument) {
1112 if (logger.isEnabledFor(Level.WARN)) {
1113 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1114 }
1115 }
1116
1117 /***
1118 * Log a parameterized message at warn level.
1119 * @param logger logger, may not be null.
1120 * @param pattern pattern, may be null.
1121 * @param argument a value to be formatted and substituted.
1122 */
1123 public static void warn(final Logger logger, final String pattern,
1124 final Object argument) {
1125 if (logger.isEnabledFor(Level.WARN)) {
1126 forcedLog(logger, Level.WARN, format(pattern, argument));
1127 }
1128 }
1129
1130 /***
1131 * Log a parameterized message at warn level.
1132 * @param logger logger, may not be null.
1133 * @param pattern pattern, may be null.
1134 * @param arg0 a value to be formatted and substituted.
1135 * @param arg1 a value to be formatted and substituted.
1136 */
1137 public static void warn(final Logger logger, final String pattern,
1138 final Object arg0, final Object arg1) {
1139 if (logger.isEnabledFor(Level.WARN)) {
1140 forcedLog(logger, Level.WARN,
1141 format(pattern, toArray(arg0, arg1)));
1142 }
1143 }
1144
1145 /***
1146 * Log a parameterized message at warn level.
1147 * @param logger logger, may not be null.
1148 * @param pattern pattern, may be null.
1149 * @param arg0 a value to be formatted and substituted.
1150 * @param arg1 a value to be formatted and substituted.
1151 * @param arg2 a value to be formatted and substituted.
1152 */
1153 public static void warn(final Logger logger, final String pattern,
1154 final Object arg0, final Object arg1, final Object arg2) {
1155 if (logger.isEnabledFor(Level.WARN)) {
1156 forcedLog(logger, Level.WARN,
1157 format(pattern, toArray(arg0, arg1, arg2)));
1158 }
1159 }
1160
1161 /***
1162 * Log a parameterized message at warn level.
1163 * @param logger logger, may not be null.
1164 * @param pattern pattern, may be null.
1165 * @param arg0 a value to be formatted and substituted.
1166 * @param arg1 a value to be formatted and substituted.
1167 * @param arg2 a value to be formatted and substituted.
1168 * @param arg3 a value to be formatted and substituted.
1169 */
1170 public static void warn(final Logger logger, final String pattern,
1171 final Object arg0, final Object arg1, final Object arg2,
1172 final Object arg3) {
1173 if (logger.isEnabledFor(Level.WARN)) {
1174 forcedLog(logger, Level.WARN, format(pattern,
1175 toArray(arg0, arg1, arg2, arg3)));
1176 }
1177 }
1178
1179 /***
1180 * Log a parameterized message at specified level.
1181 * @param logger logger, may not be null.
1182 * @param level level, may not be null.
1183 * @param pattern pattern, may be null.
1184 * @param parameters parameters to the log message.
1185 */
1186 public static void log(final Logger logger,
1187 final Level level,
1188 final String pattern,
1189 final Object[] parameters) {
1190 if (logger.isEnabledFor(level)) {
1191 forcedLog(logger, level,
1192 format(pattern, parameters));
1193 }
1194 }
1195
1196 /***
1197 * Log a parameterized message at specified level.
1198 * @param logger logger, may not be null.
1199 * @param level level, may not be null.
1200 * @param t throwable, may be null.
1201 * @param pattern pattern, may be null.
1202 * @param parameters parameters to the log message.
1203 */
1204 public static void log(final Logger logger,
1205 final Level level,
1206 final Throwable t,
1207 final String pattern,
1208 final Object[] parameters) {
1209 if (logger.isEnabledFor(level)) {
1210 forcedLog(logger, level,
1211 format(pattern, parameters), t);
1212 }
1213 }
1214
1215 /***
1216 * Log a parameterized message at specified level.
1217 * @param logger logger, may not be null.
1218 * @param level level, may not be null.
1219 * @param pattern pattern, may be null.
1220 * @param param1 parameter to the log message.
1221 */
1222 public static void log(final Logger logger,
1223 final Level level,
1224 final String pattern,
1225 final Object param1) {
1226 if (logger.isEnabledFor(level)) {
1227 forcedLog(logger, level,
1228 format(pattern, toArray(param1)));
1229 }
1230 }
1231
1232 /***
1233 * Log a parameterized message at specified level.
1234 * @param logger logger, may not be null.
1235 * @param level level, may not be null.
1236 * @param pattern pattern, may be null.
1237 * @param param1 parameter to the log message.
1238 */
1239 public static void log(final Logger logger,
1240 final Level level,
1241 final String pattern,
1242 final boolean param1) {
1243 if (logger.isEnabledFor(level)) {
1244 forcedLog(logger, level,
1245 format(pattern, toArray(valueOf(param1))));
1246 }
1247 }
1248
1249
1250 /***
1251 * Log a parameterized message at specified level.
1252 * @param logger logger, may not be null.
1253 * @param level level, may not be null.
1254 * @param pattern pattern, may be null.
1255 * @param param1 parameter to the log message.
1256 */
1257 public static void log(final Logger logger,
1258 final Level level,
1259 final String pattern,
1260 final byte param1) {
1261 if (logger.isEnabledFor(level)) {
1262 forcedLog(logger, level,
1263 format(pattern, toArray(valueOf(param1))));
1264 }
1265 }
1266
1267
1268 /***
1269 * Log a parameterized message at specified level.
1270 * @param logger logger, may not be null.
1271 * @param level level, may not be null.
1272 * @param pattern pattern, may be null.
1273 * @param param1 parameter to the log message.
1274 */
1275 public static void log(final Logger logger,
1276 final Level level,
1277 final String pattern,
1278 final char param1) {
1279 if (logger.isEnabledFor(level)) {
1280 forcedLog(logger, level,
1281 format(pattern, toArray(valueOf(param1))));
1282 }
1283 }
1284
1285 /***
1286 * Log a parameterized message at specified level.
1287 * @param logger logger, may not be null.
1288 * @param level level, may not be null.
1289 * @param pattern pattern, may be null.
1290 * @param param1 parameter to the log message.
1291 */
1292 public static void log(final Logger logger,
1293 final Level level,
1294 final String pattern,
1295 final short param1) {
1296 if (logger.isEnabledFor(level)) {
1297 forcedLog(logger, level,
1298 format(pattern, toArray(valueOf(param1))));
1299 }
1300 }
1301
1302 /***
1303 * Log a parameterized message at specified level.
1304 * @param logger logger, may not be null.
1305 * @param level level, may not be null.
1306 * @param pattern pattern, may be null.
1307 * @param param1 parameter to the log message.
1308 */
1309 public static void log(final Logger logger,
1310 final Level level,
1311 final String pattern,
1312 final int param1) {
1313 if (logger.isEnabledFor(level)) {
1314 forcedLog(logger, level,
1315 format(pattern, toArray(valueOf(param1))));
1316 }
1317 }
1318
1319
1320 /***
1321 * Log a parameterized message at specified level.
1322 * @param logger logger, may not be null.
1323 * @param level level, may not be null.
1324 * @param pattern pattern, may be null.
1325 * @param param1 parameter to the log message.
1326 */
1327 public static void log(final Logger logger,
1328 final Level level,
1329 final String pattern,
1330 final long param1) {
1331 if (logger.isEnabledFor(level)) {
1332 forcedLog(logger, level,
1333 format(pattern, toArray(valueOf(param1))));
1334 }
1335 }
1336
1337
1338 /***
1339 * Log a parameterized message at specified level.
1340 * @param logger logger, may not be null.
1341 * @param level level, may not be null.
1342 * @param pattern pattern, may be null.
1343 * @param param1 parameter to the log message.
1344 */
1345 public static void log(final Logger logger,
1346 final Level level,
1347 final String pattern,
1348 final float param1) {
1349 if (logger.isEnabledFor(level)) {
1350 forcedLog(logger, level,
1351 format(pattern, toArray(valueOf(param1))));
1352 }
1353 }
1354
1355
1356 /***
1357 * Log a parameterized message at specified level.
1358 * @param logger logger, may not be null.
1359 * @param level level, may not be null.
1360 * @param pattern pattern, may be null.
1361 * @param param1 parameter to the log message.
1362 */
1363 public static void log(final Logger logger,
1364 final Level level,
1365 final String pattern,
1366 final double param1) {
1367 if (logger.isEnabledFor(level)) {
1368 forcedLog(logger, level,
1369 format(pattern, toArray(valueOf(param1))));
1370 }
1371 }
1372
1373
1374 /***
1375 * Log a parameterized message at specified level.
1376 * @param logger logger, may not be null.
1377 * @param level level, may not be null.
1378 * @param pattern pattern, may be null.
1379 * @param arg0 a value to be formatted and substituted.
1380 * @param arg1 a value to be formatted and substituted.
1381 */
1382 public static void log(final Logger logger,
1383 final Level level,
1384 final String pattern,
1385 final Object arg0, final Object arg1) {
1386 if (logger.isEnabledFor(level)) {
1387 forcedLog(logger, level,
1388 format(pattern, toArray(arg0, arg1)));
1389 }
1390 }
1391
1392 /***
1393 * Log a parameterized message at specifed level.
1394 * @param logger logger, may not be null.
1395 * @param level level, may not be null.
1396 * @param pattern pattern, may be null.
1397 * @param arg0 a value to be formatted and substituted.
1398 * @param arg1 a value to be formatted and substituted.
1399 * @param arg2 a value to be formatted and substituted.
1400 */
1401 public static void log(final Logger logger,
1402 final Level level,
1403 final String pattern,
1404 final Object arg0, final Object arg1, final Object arg2) {
1405 if (logger.isEnabledFor(level)) {
1406 forcedLog(logger, level,
1407 format(pattern, toArray(arg0, arg1, arg2)));
1408 }
1409 }
1410
1411 /***
1412 * Log a parameterized message at specified level.
1413 * @param logger logger, may not be null.
1414 * @param pattern pattern, may be null.
1415 * @param level level, may not be null.
1416 * @param arg0 a value to be formatted and substituted.
1417 * @param arg1 a value to be formatted and substituted.
1418 * @param arg2 a value to be formatted and substituted.
1419 * @param arg3 a value to be formatted and substituted.
1420 */
1421 public static void log(final Logger logger,
1422 final Level level,
1423 final String pattern,
1424 final Object arg0, final Object arg1, final Object arg2,
1425 final Object arg3) {
1426 if (logger.isEnabledFor(level)) {
1427 forcedLog(logger, level, format(pattern,
1428 toArray(arg0, arg1, arg2, arg3)));
1429 }
1430 }
1431
1432
1433 /***
1434 * Log a parameterized message using a pattern from a resource bundle.
1435 * @param logger logger, may not be null.
1436 * @param level level, may not be null.
1437 * @param bundleName resource bundle name, may be null.
1438 * @param key key, may be null.
1439 * @param parameters parameters to the log message.
1440 */
1441 public static void logrb(final Logger logger,
1442 final Level level,
1443 final String bundleName,
1444 final String key,
1445 final Object[] parameters) {
1446 if (logger.isEnabledFor(level)) {
1447 forcedLog(logger, level,
1448 format(bundleName, key, parameters));
1449 }
1450 }
1451
1452 /***
1453 * Log a parameterized message using a pattern from a resource bundle.
1454 * @param logger logger, may not be null.
1455 * @param level level, may not be null.
1456 * @param t throwable, may be null.
1457 * @param bundleName resource bundle name, may be null.
1458 * @param key key, may be null.
1459 * @param parameters parameters to the log message.
1460 */
1461 public static void logrb(final Logger logger,
1462 final Level level,
1463 final Throwable t,
1464 final String bundleName,
1465 final String key,
1466 final Object[] parameters) {
1467 if (logger.isEnabledFor(level)) {
1468 forcedLog(logger, level,
1469 format(bundleName, key, parameters), t);
1470 }
1471 }
1472
1473 /***
1474 * Log a parameterized message using a pattern from a resource bundle.
1475 * @param logger logger, may not be null.
1476 * @param level level, may not be null.
1477 * @param bundleName resource bundle name, may be null.
1478 * @param key key, may be null.
1479 * @param param1 Parameter to the log message.
1480 */
1481 public static void logrb(final Logger logger,
1482 final Level level,
1483 final String bundleName,
1484 final String key,
1485 final Object param1) {
1486 if (logger.isEnabledFor(level)) {
1487 forcedLog(logger, level,
1488 format(bundleName, key, toArray(param1)));
1489 }
1490 }
1491
1492 /***
1493 * Log a parameterized message using a pattern from a resource bundle.
1494 * @param logger logger, may not be null.
1495 * @param level level, may not be null.
1496 * @param bundleName resource bundle name, may be null.
1497 * @param key key, may be null.
1498 * @param param1 Parameter to the log message.
1499 */
1500 public static void logrb(final Logger logger,
1501 final Level level,
1502 final String bundleName,
1503 final String key,
1504 final boolean param1) {
1505 if (logger.isEnabledFor(level)) {
1506 forcedLog(logger, level,
1507 format(bundleName, key, toArray(valueOf(param1))));
1508 }
1509 }
1510
1511 /***
1512 * Log a parameterized message using a pattern from a resource bundle.
1513 * @param logger logger, may not be null.
1514 * @param level level, may not be null.
1515 * @param bundleName resource bundle name, may be null.
1516 * @param key key, may be null.
1517 * @param param1 Parameter to the log message.
1518 */
1519 public static void logrb(final Logger logger,
1520 final Level level,
1521 final String bundleName,
1522 final String key,
1523 final char param1) {
1524 if (logger.isEnabledFor(level)) {
1525 forcedLog(logger, level,
1526 format(bundleName, key, toArray(valueOf(param1))));
1527 }
1528 }
1529
1530 /***
1531 * Log a parameterized message using a pattern from a resource bundle.
1532 * @param logger logger, may not be null.
1533 * @param level level, may not be null.
1534 * @param bundleName resource bundle name, may be null.
1535 * @param key key, may be null.
1536 * @param param1 Parameter to the log message.
1537 */
1538 public static void logrb(final Logger logger,
1539 final Level level,
1540 final String bundleName,
1541