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