2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.log4j;
19 import org.apache.log4j.spi.LoggingEvent;
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 import java.util.Locale;
30 * This class provides parameterized logging services
31 * using the pattern syntax of java.text.MessageFormat.
32 * Message formatting is only performed when the
33 * request exceeds the threshold level of the logger.
34 * When the pattern only contains literal text and
35 * default conversion patterns (that is "{0}" and similar)
36 * a simple fast compatible formatter is used.
37 * If the pattern contains more complex conversion patterns,
38 * formatting will be delegated to java.text.MessageFormatter
39 * which can be substantially slower.
41 * @see org.apache.log4j.LogSF
45 public final class LogMF extends LogXF {
47 * private constructor.
56 private static NumberFormat numberFormat = null;
58 * Locale at time of last number format request.
60 private static Locale numberLocale = null;
64 private static DateFormat dateFormat = null;
66 * Locale at time of last date format request.
68 private static Locale dateLocale = null;
72 * @param n number to format, may not be null.
73 * @return formatted value.
75 private static synchronized String formatNumber(final Object n) {
76 Locale currentLocale = Locale.getDefault();
77 if (currentLocale != numberLocale || numberFormat == null) {
78 numberLocale = currentLocale;
79 numberFormat = NumberFormat.getInstance(currentLocale);
81 return numberFormat.format(n);
87 * @param d date, may not be null.
88 * @return formatted value.
90 private static synchronized String formatDate(final Object d) {
91 Locale currentLocale = Locale.getDefault();
92 if (currentLocale != dateLocale || dateFormat == null) {
93 dateLocale = currentLocale;
94 dateFormat = DateFormat.getDateTimeInstance(
99 return dateFormat.format(d);
103 * Format a single parameter like a "{0}" formatting specifier.
105 * @param arg0 parameter, may be null.
106 * @return string representation of arg0.
108 private static String formatObject(final Object arg0) {
109 if (arg0 instanceof String) {
110 return arg0.toString();
111 } else if (arg0 instanceof Double ||
112 arg0 instanceof Float) {
113 return formatNumber(arg0);
114 } else if (arg0 instanceof Date) {
115 return formatDate(arg0);
117 return String.valueOf(arg0);
122 * Determines if pattern contains only {n} format elements
123 * and not apostrophes.
125 * @param pattern pattern, may not be null.
126 * @return true if pattern only contains {n} format elements.
128 private static boolean isSimple(final String pattern) {
129 if (pattern.indexOf('\'') != -1) {
132 for(int pos = pattern.indexOf('{');
134 pos = pattern.indexOf('{', pos + 1)) {
135 if (pos + 2 >= pattern.length() ||
136 pattern.charAt(pos+2) != '}' ||
137 pattern.charAt(pos+1) < '0' ||
138 pattern.charAt(pos+1) > '9') {
147 * Formats arguments using MessageFormat.
148 * @param pattern pattern, may be malformed or null.
149 * @param arguments arguments, may be null or mismatched.
150 * @return Message string or null
152 private static String format(final String pattern,
153 final Object[] arguments) {
154 if (pattern == null) {
156 } else if(isSimple(pattern)) {
157 String formatted[] = new String[10];
160 int pos = pattern.indexOf('{');
162 if(pos + 2 < pattern.length() &&
163 pattern.charAt(pos+2) == '}' &&
164 pattern.charAt(pos+1) >= '0' &&
165 pattern.charAt(pos+1) <= '9') {
166 int index = pattern.charAt(pos+1) - '0';
167 retval += pattern.substring(prev, pos);
168 if (formatted[index] == null) {
169 if (arguments == null || index >= arguments.length) {
170 formatted[index] = pattern.substring(pos, pos+3);
172 formatted[index] = formatObject(arguments[index]);
175 retval += formatted[index];
177 pos = pattern.indexOf('{', prev);
179 pos = pattern.indexOf('{', pos + 1);
182 retval += pattern.substring(prev);
186 return MessageFormat.format(pattern, arguments);
187 } catch (IllegalArgumentException ex) {
193 * Formats a single argument using MessageFormat.
194 * @param pattern pattern, may be malformed or null.
195 * @param arguments arguments, may be null or mismatched.
196 * @return Message string or null
198 private static String format(final String pattern,
200 if (pattern == null) {
202 } else if(isSimple(pattern)) {
203 String formatted = null;
206 int pos = pattern.indexOf('{');
208 if(pos + 2 < pattern.length() &&
209 pattern.charAt(pos+2) == '}' &&
210 pattern.charAt(pos+1) >= '0' &&
211 pattern.charAt(pos+1) <= '9') {
212 int index = pattern.charAt(pos+1) - '0';
213 retval += pattern.substring(prev, pos);
215 retval += pattern.substring(pos, pos+3);
217 if (formatted == null) {
218 formatted = formatObject(arg0);
223 pos = pattern.indexOf('{', prev);
225 pos = pattern.indexOf('{', pos + 1);
228 retval += pattern.substring(prev);
232 return MessageFormat.format(pattern, new Object[] { arg0 });
233 } catch (IllegalArgumentException ex) {
240 * Formats arguments using MessageFormat using a pattern from
242 * @param resourceBundleName name of resource bundle, may be null.
243 * @param key key for pattern in resource bundle, may be null.
244 * @param arguments arguments, may be null or mismatched.
245 * @return Message string or null
247 private static String format(
248 final String resourceBundleName,
250 final Object[] arguments) {
252 if (resourceBundleName != null) {
254 ResourceBundle bundle =
255 ResourceBundle.getBundle(resourceBundleName);
256 pattern = bundle.getString(key);
257 } catch (Exception ex) {
263 return format(pattern, arguments);
268 * Fully Qualified Class Name of this class.
270 private static final String FQCN = LogMF.class.getName();
273 * Equivalent of Logger.forcedLog.
275 * @param logger logger, may not be null.
276 * @param level level, may not be null.
277 * @param msg message, may be null.
279 private static void forcedLog(final Logger logger,
282 logger.callAppenders(new LoggingEvent(FQCN, logger, level, msg, null));
286 * Equivalent of Logger.forcedLog.
288 * @param logger logger, may not be null.
289 * @param level level, may not be null.
290 * @param msg message, may be null.
291 * @param t throwable.
293 private static void forcedLog(final Logger logger,
297 logger.callAppenders(new LoggingEvent(FQCN, logger, level, msg, t));
300 * Log a parameterized message at trace level.
301 * @param logger logger, may not be null.
302 * @param pattern pattern, may be null.
303 * @param arguments an array of arguments to be
304 * formatted and substituted.
306 public static void trace(final Logger logger, final String pattern,
307 final Object[] arguments) {
308 if (logger.isEnabledFor(TRACE)) {
309 forcedLog(logger, TRACE, format(pattern, arguments));
314 * Log a parameterized message at debug level.
315 * @param logger logger, may not be null.
316 * @param pattern pattern, may be null.
317 * @param arguments an array of arguments to be formatted and substituted.
319 public static void debug(final Logger logger, final String pattern,
320 final Object[] arguments) {
321 if (logger.isDebugEnabled()) {
322 forcedLog(logger, Level.DEBUG, format(pattern, arguments));
327 * Log a parameterized message at info level.
328 * @param logger logger, may not be null.
329 * @param pattern pattern, may be null.
330 * @param arguments an array of arguments to be formatted and substituted.
332 public static void info(final Logger logger, final String pattern,
333 final Object[] arguments) {
334 if (logger.isInfoEnabled()) {
335 forcedLog(logger, Level.INFO, format(pattern, arguments));
340 * Log a parameterized message at warn level.
341 * @param logger logger, may not be null.
342 * @param pattern pattern, may be null.
343 * @param arguments an array of arguments to be formatted and substituted.
345 public static void warn(final Logger logger, final String pattern,
346 final Object[] arguments) {
347 if (logger.isEnabledFor(Level.WARN)) {
348 forcedLog(logger, Level.WARN, format(pattern, arguments));
353 * Log a parameterized message at error 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.
358 public static void error(final Logger logger, final String pattern,
359 final Object[] arguments) {
360 if (logger.isEnabledFor(Level.ERROR)) {
361 forcedLog(logger, Level.ERROR, format(pattern, arguments));
366 * Log a parameterized message at fatal 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.
371 public static void fatal(final Logger logger, final String pattern,
372 final Object[] arguments) {
373 if (logger.isEnabledFor(Level.FATAL)) {
374 forcedLog(logger, Level.FATAL, format(pattern, arguments));
379 * Log a parameterized message at trace 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
384 * formatted and substituted.
386 public static void trace(final Logger logger,
388 final String pattern,
389 final Object[] arguments) {
390 if (logger.isEnabledFor(TRACE)) {
391 forcedLog(logger, TRACE, format(pattern, arguments), t);
396 * Log a parameterized message at debug level.
397 * @param logger logger, may not be null.
398 * @param t throwable, may be null.
399 * @param pattern pattern, may be null.
400 * @param arguments an array of arguments to be formatted and substituted.
402 public static void debug(final Logger logger,
404 final String pattern,
405 final Object[] arguments) {
406 if (logger.isDebugEnabled()) {
407 forcedLog(logger, Level.DEBUG, format(pattern, arguments), t);
412 * Log a parameterized message at info level.
413 * @param logger logger, may not be null.
414 * @param t throwable, may be null.
415 * @param pattern pattern, may be null.
416 * @param arguments an array of arguments to be formatted and substituted.
418 public static void info(final Logger logger,
420 final String pattern,
421 final Object[] arguments) {
422 if (logger.isInfoEnabled()) {
423 forcedLog(logger, Level.INFO, format(pattern, arguments), t);
428 * Log a parameterized message at warn level.
429 * @param logger logger, may not be null.
430 * @param t throwable, may be null.
431 * @param pattern pattern, may be null.
432 * @param arguments an array of arguments to be formatted and substituted.
434 public static void warn(final Logger logger,
436 final String pattern,
437 final Object[] arguments) {
438 if (logger.isEnabledFor(Level.WARN)) {
439 forcedLog(logger, Level.WARN, format(pattern, arguments), t);
444 * Log a parameterized message at error level.
445 * @param logger logger, may not be null.
446 * @param t throwable, may be null.
447 * @param pattern pattern, may be null.
448 * @param arguments an array of arguments to be formatted and substituted.
450 public static void error(final Logger logger,
452 final String pattern,
453 final Object[] arguments) {
454 if (logger.isEnabledFor(Level.ERROR)) {
455 forcedLog(logger, Level.ERROR, format(pattern, arguments), t);
460 * Log a parameterized message at fatal level.
461 * @param logger logger, may not be null.
462 * @param t throwable, may be null.
463 * @param pattern pattern, may be null.
464 * @param arguments an array of arguments to be formatted and substituted.
466 public static void fatal(final Logger logger,
468 final String pattern,
469 final Object[] arguments) {
470 if (logger.isEnabledFor(Level.FATAL)) {
471 forcedLog(logger, Level.FATAL, format(pattern, arguments), t);
478 * Log a parameterized message at trace level.
479 * @param logger logger, may not be null.
480 * @param pattern pattern, may be null.
481 * @param argument a value to be formatted and substituted.
483 public static void trace(final Logger logger, final String pattern,
484 final boolean argument) {
485 if (logger.isEnabledFor(TRACE)) {
486 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
491 * Log a parameterized message at trace level.
492 * @param logger logger, may not be null.
493 * @param pattern pattern, may be null.
494 * @param argument a value to be formatted and substituted.
496 public static void trace(final Logger logger, final String pattern,
497 final char argument) {
498 if (logger.isEnabledFor(TRACE)) {
499 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
504 * Log a parameterized message at trace level.
505 * @param logger logger, may not be null.
506 * @param pattern pattern, may be null.
507 * @param argument a value to be formatted and substituted.
509 public static void trace(final Logger logger, final String pattern,
510 final byte argument) {
511 if (logger.isEnabledFor(TRACE)) {
512 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
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.
522 public static void trace(final Logger logger, final String pattern,
523 final short argument) {
524 if (logger.isEnabledFor(TRACE)) {
525 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
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.
535 public static void trace(final Logger logger, final String pattern,
536 final int argument) {
537 if (logger.isEnabledFor(TRACE)) {
538 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
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.
548 public static void trace(final Logger logger, final String pattern,
549 final long argument) {
550 if (logger.isEnabledFor(TRACE)) {
551 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
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.
561 public static void trace(final Logger logger, final String pattern,
562 final float argument) {
563 if (logger.isEnabledFor(TRACE)) {
564 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
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.
574 public static void trace(final Logger logger, final String pattern,
575 final double argument) {
576 if (logger.isEnabledFor(TRACE)) {
577 forcedLog(logger, TRACE, format(pattern, valueOf(argument)));
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.
587 public static void trace(final Logger logger, final String pattern,
588 final Object argument) {
589 if (logger.isEnabledFor(TRACE)) {
590 forcedLog(logger, TRACE, format(pattern, argument));
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 arg0 a value to be formatted and substituted.
599 * @param arg1 a value to be formatted and substituted.
601 public static void trace(final Logger logger, final String pattern,
602 final Object arg0, final Object arg1) {
603 if (logger.isEnabledFor(TRACE)) {
604 forcedLog(logger, TRACE,
605 format(pattern, toArray(arg0, arg1)));
610 * Log a parameterized message at trace level.
611 * @param logger logger, may not be null.
612 * @param pattern pattern, may be null.
613 * @param arg0 a value to be formatted and substituted.
614 * @param arg1 a value to be formatted and substituted.
615 * @param arg2 a value to be formatted and substituted.
617 public static void trace(final Logger logger, final String pattern,
618 final Object arg0, final Object arg1, final Object arg2) {
619 if (logger.isEnabledFor(TRACE)) {
620 forcedLog(logger, TRACE,
621 format(pattern, toArray(arg0, arg1, arg2)));
626 * Log a parameterized message at trace level.
627 * @param logger logger, may not be null.
628 * @param pattern pattern, may be null.
629 * @param arg0 a value to be formatted and substituted.
630 * @param arg1 a value to be formatted and substituted.
631 * @param arg2 a value to be formatted and substituted.
632 * @param arg3 a value to be formatted and substituted.
634 public static void trace(final Logger logger, final String pattern,
635 final Object arg0, final Object arg1, final Object arg2,
637 if (logger.isEnabledFor(TRACE)) {
638 forcedLog(logger, TRACE,
639 format(pattern, toArray(arg0, arg1, arg2, arg3)));
644 * Log a parameterized message at debug level.
645 * @param logger logger, may not be null.
646 * @param pattern pattern, may be null.
647 * @param argument a value to be formatted and substituted.
649 public static void debug(final Logger logger, final String pattern,
650 final boolean argument) {
651 if (logger.isDebugEnabled()) {
652 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
657 * Log a parameterized message at debug level.
658 * @param logger logger, may not be null.
659 * @param pattern pattern, may be null.
660 * @param argument a value to be formatted and substituted.
662 public static void debug(final Logger logger, final String pattern,
663 final char argument) {
664 if (logger.isDebugEnabled()) {
665 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
670 * Log a parameterized message at debug level.
671 * @param logger logger, may not be null.
672 * @param pattern pattern, may be null.
673 * @param argument a value to be formatted and substituted.
675 public static void debug(final Logger logger, final String pattern,
676 final byte argument) {
677 if (logger.isDebugEnabled()) {
678 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
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.
688 public static void debug(final Logger logger, final String pattern,
689 final short argument) {
690 if (logger.isDebugEnabled()) {
691 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
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.
701 public static void debug(final Logger logger, final String pattern,
702 final int argument) {
703 if (logger.isDebugEnabled()) {
704 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
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.
714 public static void debug(final Logger logger, final String pattern,
715 final long argument) {
716 if (logger.isDebugEnabled()) {
717 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
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.
727 public static void debug(final Logger logger, final String pattern,
728 final float argument) {
729 if (logger.isDebugEnabled()) {
730 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
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.
740 public static void debug(final Logger logger, final String pattern,
741 final double argument) {
742 if (logger.isDebugEnabled()) {
743 forcedLog(logger, Level.DEBUG, format(pattern, valueOf(argument)));
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.
753 public static void debug(final Logger logger, final String pattern,
754 final Object argument) {
755 if (logger.isDebugEnabled()) {
756 forcedLog(logger, Level.DEBUG, format(pattern, argument));
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 arg0 a value to be formatted and substituted.
765 * @param arg1 a value to be formatted and substituted.
767 public static void debug(final Logger logger, final String pattern,
768 final Object arg0, final Object arg1) {
769 if (logger.isDebugEnabled()) {
770 forcedLog(logger, Level.DEBUG,
771 format(pattern, toArray(arg0, arg1)));
776 * Log a parameterized message at debug level.
777 * @param logger logger, may not be null.
778 * @param pattern pattern, may be null.
779 * @param arg0 a value to be formatted and substituted.
780 * @param arg1 a value to be formatted and substituted.
781 * @param arg2 a value to be formatted and substituted.
783 public static void debug(final Logger logger, final String pattern,
784 final Object arg0, final Object arg1, final Object arg2) {
785 if (logger.isDebugEnabled()) {
786 forcedLog(logger, Level.DEBUG,
787 format(pattern, toArray(arg0, arg1, arg2)));
792 * Log a parameterized message at debug level.
793 * @param logger logger, may not be null.
794 * @param pattern pattern, may be null.
795 * @param arg0 a value to be formatted and substituted.
796 * @param arg1 a value to be formatted and substituted.
797 * @param arg2 a value to be formatted and substituted.
798 * @param arg3 a value to be formatted and substituted.
800 public static void debug(final Logger logger, final String pattern,
801 final Object arg0, final Object arg1, final Object arg2,
803 if (logger.isDebugEnabled()) {
804 forcedLog(logger, Level.DEBUG,
805 format(pattern, toArray(arg0, arg1, arg2, arg3)));
810 * Log a parameterized message at info level.
811 * @param logger logger, may not be null.
812 * @param pattern pattern, may be null.
813 * @param argument a value to be formatted and substituted.
815 public static void info(final Logger logger, final String pattern,
816 final boolean argument) {
817 if (logger.isInfoEnabled()) {
818 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
823 * Log a parameterized message at info level.
824 * @param logger logger, may not be null.
825 * @param pattern pattern, may be null.
826 * @param argument a value to be formatted and substituted.
828 public static void info(final Logger logger, final String pattern,
829 final char argument) {
830 if (logger.isInfoEnabled()) {
831 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
836 * Log a parameterized message at info level.
837 * @param logger logger, may not be null.
838 * @param pattern pattern, may be null.
839 * @param argument a value to be formatted and substituted.
841 public static void info(final Logger logger, final String pattern,
842 final byte argument) {
843 if (logger.isInfoEnabled()) {
844 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
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.
854 public static void info(final Logger logger, final String pattern,
855 final short argument) {
856 if (logger.isInfoEnabled()) {
857 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
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.
867 public static void info(final Logger logger, final String pattern,
868 final int argument) {
869 if (logger.isInfoEnabled()) {
870 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
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.
880 public static void info(final Logger logger, final String pattern,
881 final long argument) {
882 if (logger.isInfoEnabled()) {
883 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
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.
893 public static void info(final Logger logger, final String pattern,
894 final float argument) {
895 if (logger.isInfoEnabled()) {
896 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
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.
906 public static void info(final Logger logger, final String pattern,
907 final double argument) {
908 if (logger.isInfoEnabled()) {
909 forcedLog(logger, Level.INFO, format(pattern, valueOf(argument)));
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.
919 public static void info(final Logger logger, final String pattern,
920 final Object argument) {
921 if (logger.isInfoEnabled()) {
922 forcedLog(logger, Level.INFO, format(pattern, argument));
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 arg0 a value to be formatted and substituted.
931 * @param arg1 a value to be formatted and substituted.
933 public static void info(final Logger logger, final String pattern,
934 final Object arg0, final Object arg1) {
935 if (logger.isInfoEnabled()) {
936 forcedLog(logger, Level.INFO, format(pattern, toArray(arg0, arg1)));
941 * Log a parameterized message at info level.
942 * @param logger logger, may not be null.
943 * @param pattern pattern, may be null.
944 * @param arg0 a value to be formatted and substituted.
945 * @param arg1 a value to be formatted and substituted.
946 * @param arg2 a value to be formatted and substituted.
948 public static void info(final Logger logger, final String pattern,
949 final Object arg0, final Object arg1, final Object arg2) {
950 if (logger.isInfoEnabled()) {
951 forcedLog(logger, Level.INFO, format(pattern,
952 toArray(arg0, arg1, arg2)));
957 * Log a parameterized message at info level.
958 * @param logger logger, may not be null.
959 * @param pattern pattern, may be null.
960 * @param arg0 a value to be formatted and substituted.
961 * @param arg1 a value to be formatted and substituted.
962 * @param arg2 a value to be formatted and substituted.
963 * @param arg3 a value to be formatted and substituted.
965 public static void info(final Logger logger, final String pattern,
966 final Object arg0, final Object arg1, final Object arg2,
968 if (logger.isInfoEnabled()) {
969 forcedLog(logger, Level.INFO, format(pattern,
970 toArray(arg0, arg1, arg2, arg3)));
975 * Log a parameterized message at warn level.
976 * @param logger logger, may not be null.
977 * @param pattern pattern, may be null.
978 * @param argument a value to be formatted and substituted.
980 public static void warn(final Logger logger, final String pattern,
981 final boolean argument) {
982 if (logger.isEnabledFor(Level.WARN)) {
983 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
988 * Log a parameterized message at warn level.
989 * @param logger logger, may not be null.
990 * @param pattern pattern, may be null.
991 * @param argument a value to be formatted and substituted.
993 public static void warn(final Logger logger, final String pattern,
994 final char argument) {
995 if (logger.isEnabledFor(Level.WARN)) {
996 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
1001 * Log a parameterized message at warn level.
1002 * @param logger logger, may not be null.
1003 * @param pattern pattern, may be null.
1004 * @param argument a value to be formatted and substituted.
1006 public static void warn(final Logger logger, final String pattern,
1007 final byte argument) {
1008 if (logger.isEnabledFor(Level.WARN)) {
1009 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
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.
1019 public static void warn(final Logger logger, final String pattern,
1020 final short argument) {
1021 if (logger.isEnabledFor(Level.WARN)) {
1022 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
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.
1032 public static void warn(final Logger logger, final String pattern,
1033 final int argument) {
1034 if (logger.isEnabledFor(Level.WARN)) {
1035 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
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.
1045 public static void warn(final Logger logger, final String pattern,
1046 final long argument) {
1047 if (logger.isEnabledFor(Level.WARN)) {
1048 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
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.
1058 public static void warn(final Logger logger, final String pattern,
1059 final float argument) {
1060 if (logger.isEnabledFor(Level.WARN)) {
1061 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
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.
1071 public static void warn(final Logger logger, final String pattern,
1072 final double argument) {
1073 if (logger.isEnabledFor(Level.WARN)) {
1074 forcedLog(logger, Level.WARN, format(pattern, valueOf(argument)));
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.
1084 public static void warn(final Logger logger, final String pattern,
1085 final Object argument) {
1086 if (logger.isEnabledFor(Level.WARN)) {
1087 forcedLog(logger, Level.WARN, format(pattern, argument));
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 arg0 a value to be formatted and substituted.
1096 * @param arg1 a value to be formatted and substituted.
1098 public static void warn(final Logger logger, final String pattern,
1099 final Object arg0, final Object arg1) {
1100 if (logger.isEnabledFor(Level.WARN)) {
1101 forcedLog(logger, Level.WARN,
1102 format(pattern, toArray(arg0, arg1)));
1107 * Log a parameterized message at warn level.
1108 * @param logger logger, may not be null.
1109 * @param pattern pattern, may be null.
1110 * @param arg0 a value to be formatted and substituted.
1111 * @param arg1 a value to be formatted and substituted.
1112 * @param arg2 a value to be formatted and substituted.
1114 public static void warn(final Logger logger, final String pattern,
1115 final Object arg0, final Object arg1, final Object arg2) {
1116 if (logger.isEnabledFor(Level.WARN)) {
1117 forcedLog(logger, Level.WARN,
1118 format(pattern, toArray(arg0, arg1, arg2)));
1123 * Log a parameterized message at warn level.
1124 * @param logger logger, may not be null.
1125 * @param pattern pattern, may be null.
1126 * @param arg0 a value to be formatted and substituted.
1127 * @param arg1 a value to be formatted and substituted.
1128 * @param arg2 a value to be formatted and substituted.
1129 * @param arg3 a value to be formatted and substituted.
1131 public static void warn(final Logger logger, final String pattern,
1132 final Object arg0, final Object arg1, final Object arg2,
1133 final Object arg3) {
1134 if (logger.isEnabledFor(Level.WARN)) {
1135 forcedLog(logger, Level.WARN, format(pattern,
1136 toArray(arg0, arg1, arg2, arg3)));
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 pattern pattern, may be null.
1145 * @param parameters parameters to the log message.
1147 public static void log(final Logger logger,
1149 final String pattern,
1150 final Object[] parameters) {
1151 if (logger.isEnabledFor(level)) {
1152 forcedLog(logger, level,
1153 format(pattern, parameters));
1158 * Log a parameterized message at specified level.
1159 * @param logger logger, may not be null.
1160 * @param level level, may not be null.
1161 * @param t throwable, may be null.
1162 * @param pattern pattern, may be null.
1163 * @param parameters parameters to the log message.
1165 public static void log(final Logger logger,
1168 final String pattern,
1169 final Object[] parameters) {
1170 if (logger.isEnabledFor(level)) {
1171 forcedLog(logger, level,
1172 format(pattern, parameters), t);
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.
1183 public static void log(final Logger logger,
1185 final String pattern,
1186 final Object param1) {
1187 if (logger.isEnabledFor(level)) {
1188 forcedLog(logger, level,
1189 format(pattern, toArray(param1)));
1194 * Log a parameterized message at specified level.
1195 * @param logger logger, may not be null.
1196 * @param level level, may not be null.
1197 * @param pattern pattern, may be null.
1198 * @param param1 parameter to the log message.
1200 public static void log(final Logger logger,
1202 final String pattern,
1203 final boolean param1) {
1204 if (logger.isEnabledFor(level)) {
1205 forcedLog(logger, level,
1206 format(pattern, toArray(valueOf(param1))));
1212 * Log a parameterized message at specified level.
1213 * @param logger logger, may not be null.
1214 * @param level level, may not be null.
1215 * @param pattern pattern, may be null.
1216 * @param param1 parameter to the log message.
1218 public static void log(final Logger logger,
1220 final String pattern,
1221 final byte param1) {
1222 if (logger.isEnabledFor(level)) {
1223 forcedLog(logger, level,
1224 format(pattern, toArray(valueOf(param1))));
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.
1236 public static void log(final Logger logger,
1238 final String pattern,
1239 final char param1) {
1240 if (logger.isEnabledFor(level)) {
1241 forcedLog(logger, level,
1242 format(pattern, toArray(valueOf(param1))));
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.
1253 public static void log(final Logger logger,
1255 final String pattern,
1256 final short param1) {
1257 if (logger.isEnabledFor(level)) {
1258 forcedLog(logger, level,
1259 format(pattern, toArray(valueOf(param1))));
1264 * Log a parameterized message at specified level.
1265 * @param logger logger, may not be null.
1266 * @param level level, may not be null.
1267 * @param pattern pattern, may be null.
1268 * @param param1 parameter to the log message.
1270 public static void log(final Logger logger,
1272 final String pattern,
1274 if (logger.isEnabledFor(level)) {
1275 forcedLog(logger, level,
1276 format(pattern, toArray(valueOf(param1))));
1282 * Log a parameterized message at specified level.
1283 * @param logger logger, may not be null.
1284 * @param level level, may not be null.
1285 * @param pattern pattern, may be null.
1286 * @param param1 parameter to the log message.
1288 public static void log(final Logger logger,
1290 final String pattern,
1291 final long param1) {
1292 if (logger.isEnabledFor(level)) {
1293 forcedLog(logger, level,
1294 format(pattern, toArray(valueOf(param1))));
1300 * Log a parameterized message at specified level.
1301 * @param logger logger, may not be null.
1302 * @param level level, may not be null.
1303 * @param pattern pattern, may be null.
1304 * @param param1 parameter to the log message.
1306 public static void log(final Logger logger,
1308 final String pattern,
1309 final float param1) {
1310 if (logger.isEnabledFor(level)) {
1311 forcedLog(logger, level,
1312 format(pattern, toArray(valueOf(param1))));
1318 * Log a parameterized message at specified level.
1319 * @param logger logger, may not be null.
1320 * @param level level, may not be null.
1321 * @param pattern pattern, may be null.
1322 * @param param1 parameter to the log message.
1324 public static void log(final Logger logger,
1326 final String pattern,
1327 final double param1) {
1328 if (logger.isEnabledFor(level)) {
1329 forcedLog(logger, level,
1330 format(pattern, toArray(valueOf(param1))));
1336 * Log a parameterized message at specified level.
1337 * @param logger logger, may not be null.
1338 * @param level level, may not be null.
1339 * @param pattern pattern, may be null.
1340 * @param arg0 a value to be formatted and substituted.
1341 * @param arg1 a value to be formatted and substituted.
1343 public static void log(final Logger logger,
1345 final String pattern,
1346 final Object arg0, final Object arg1) {
1347 if (logger.isEnabledFor(level)) {
1348 forcedLog(logger, level,
1349 format(pattern, toArray(arg0, arg1)));
1354 * Log a parameterized message at specifed level.
1355 * @param logger logger, may not be null.
1356 * @param level level, may not be null.
1357 * @param pattern pattern, may be null.
1358 * @param arg0 a value to be formatted and substituted.
1359 * @param arg1 a value to be formatted and substituted.
1360 * @param arg2 a value to be formatted and substituted.
1362 public static void log(final Logger logger,
1364 final String pattern,
1365 final Object arg0, final Object arg1, final Object arg2) {
1366 if (logger.isEnabledFor(level)) {
1367 forcedLog(logger, level,
1368 format(pattern, toArray(arg0, arg1, arg2)));
1373 * Log a parameterized message at specified level.
1374 * @param logger logger, may not be null.
1375 * @param pattern pattern, may be null.
1376 * @param level level, may not be null.
1377 * @param arg0 a value to be formatted and substituted.
1378 * @param arg1 a value to be formatted and substituted.
1379 * @param arg2 a value to be formatted and substituted.
1380 * @param arg3 a value to be formatted and substituted.
1382 public static void log(final Logger logger,
1384 final String pattern,
1385 final Object arg0, final Object arg1, final Object arg2,
1386 final Object arg3) {
1387 if (logger.isEnabledFor(level)) {
1388 forcedLog(logger, level, format(pattern,
1389 toArray(arg0, arg1, arg2, arg3)));
1395 * Log a parameterized message using a pattern from a resource bundle.
1396 * @param logger logger, may not be null.
1397 * @param level level, may not be null.
1398 * @param bundleName resource bundle name, may be null.
1399 * @param key key, may be null.
1400 * @param parameters parameters to the log message.
1402 public static void logrb(final Logger logger,
1404 final String bundleName,
1406 final Object[] parameters) {
1407 if (logger.isEnabledFor(level)) {
1408 forcedLog(logger, level,
1409 format(bundleName, key, parameters));
1414 * Log a parameterized message using a pattern from a resource bundle.
1415 * @param logger logger, may not be null.
1416 * @param level level, may not be null.
1417 * @param t throwable, may be null.
1418 * @param bundleName resource bundle name, may be null.
1419 * @param key key, may be null.
1420 * @param parameters parameters to the log message.
1422 public static void logrb(final Logger logger,
1425 final String bundleName,
1427 final Object[] parameters) {
1428 if (logger.isEnabledFor(level)) {
1429 forcedLog(logger, level,
1430 format(bundleName, key, parameters), t);
1435 * Log a parameterized message using a pattern from a resource bundle.
1436 * @param logger logger, may not be null.
1437 * @param level level, may not be null.
1438 * @param bundleName resource bundle name, may be null.
1439 * @param key key, may be null.
1440 * @param param1 Parameter to the log message.
1442 public static void logrb(final Logger logger,
1444 final String bundleName,
1446 final Object param1) {
1447 if (logger.isEnabledFor(level)) {
1448 forcedLog(logger, level,
1449 format(bundleName, key, toArray(param1)));
1454 * Log a parameterized message using a pattern from a resource bundle.
1455 * @param logger logger, may not be null.
1456 * @param level level, may not be null.
1457 * @param bundleName resource bundle name, may be null.
1458 * @param key key, may be null.
1459 * @param param1 Parameter to the log message.
1461 public static void logrb(final Logger logger,
1463 final String bundleName,
1465 final boolean param1) {
1466 if (logger.isEnabledFor(level)) {
1467 forcedLog(logger, level,
1468 format(bundleName, key, toArray(valueOf(param1))));
1473 * Log a parameterized message using a pattern from a resource bundle.
1474 * @param logger logger, may not be null.
1475 * @param level level, may not be null.
1476 * @param bundleName resource bundle name, may be null.
1477 * @param key key, may be null.
1478 * @param param1 Parameter to the log message.
1480 public static void logrb(final Logger logger,
1482 final String bundleName,
1484 final char param1) {
1485 if (logger.isEnabledFor(level)) {
1486 forcedLog(logger, level,
1487 format(bundleName, key, toArray(valueOf(param1))));
1492 * Log a parameterized message using a pattern from a resource bundle.
1493 * @param logger logger, may not be null.
1494 * @param level level, may not be null.
1495 * @param bundleName resource bundle name, may be null.
1496 * @param key key, may be null.
1497 * @param param1 Parameter to the log message.
1499 public static void logrb(final Logger logger,
1501 final String bundleName,
1503 final byte param1) {
1504 if (logger.isEnabledFor(level)) {
1505 forcedLog(logger, level,
1506 format(bundleName, key, toArray(valueOf(param1))));
1511 * Log a parameterized message using a pattern from a resource bundle.
1512 * @param logger logger, may not be null.
1513 * @param level level, may not be null.
1514 * @param bundleName resource bundle name, may be null.
1515 * @param key key, may be null.
1516 * @param param1 Parameter to the log message.
1518 public static void logrb(final Logger logger,
1520 final String bundleName,
1522 final short param1) {
1523 if (logger.isEnabledFor(level)) {
1524 forcedLog(logger, level,
1525 format(bundleName, key, toArray(valueOf(param1))));
1530 * Log a parameterized message using a pattern from a resource bundle.
1531 * @param logger logger, may not be null.
1532 * @param level level, may not be null.
1533 * @param bundleName resource bundle name, may be null.
1534 * @param key key, may be null.
1535 * @param param1 Parameter to the log message.
1537 public static void logrb(final Logger logger,
1539 final String bundleName,
1542 if (logger.isEnabledFor(level)) {
1543 forcedLog(logger, level,
1544 format(bundleName, key, toArray(valueOf(param1))));
1549 * Log a parameterized message using a pattern from a resource bundle.
1550 * @param logger logger, may not be null.
1551 * @param level level, may not be null.
1552 * @param bundleName resource bundle name, may be null.
1553 * @param key key, may be null.
1554 * @param param1 Parameter to the log message.
1556 public static void logrb(final Logger logger,
1558 final String bundleName,
1560 final long param1) {
1561 if (logger.isEnabledFor(level)) {
1562 forcedLog(logger, level,
1563 format(bundleName, key, toArray(valueOf(param1))));
1567 * Log a parameterized message using a pattern from a resource bundle.
1568 * @param logger logger, may not be null.
1569 * @param level level, may not be null.
1570 * @param bundleName resource bundle name, may be null.
1571 * @param key key, may be null.
1572 * @param param1 Parameter to the log message.
1574 public static void logrb(final Logger logger,
1576 final String bundleName,
1578 final float param1) {
1579 if (logger.isEnabledFor(level)) {
1580 forcedLog(logger, level,
1581 format(bundleName, key, toArray(valueOf(param1))));
1587 * Log a parameterized message using a pattern from a resource bundle.
1588 * @param logger logger, may not be null.
1589 * @param level level, may not be null.
1590 * @param bundleName resource bundle name, may be null.
1591 * @param key key, may be null.
1592 * @param param1 Parameter to the log message.
1594 public static void logrb(final Logger logger,
1596 final String bundleName,
1598 final double param1) {
1599 if (logger.isEnabledFor(level)) {
1600 forcedLog(logger, level,
1601 format(bundleName, key, toArray(valueOf(param1))));
1606 * Log a parameterized message using a pattern from a resource bundle.
1607 * @param logger logger, may not be null.
1608 * @param level level, may not be null.
1609 * @param bundleName resource bundle name, may be null.
1610 * @param key key, may be null.
1611 * @param param0 Parameter to the log message.
1612 * @param param1 Parameter to the log message.
1614 public static void logrb(final Logger logger,
1616 final String bundleName,
1618 final Object param0,
1619 final Object param1) {
1620 if (logger.isEnabledFor(level)) {
1621 forcedLog(logger, level,
1622 format(bundleName, key, toArray(param0, param1)));
1628 * Log a parameterized message using a pattern from a resource bundle.
1629 * @param logger logger, may not be null.
1630 * @param level level, may not be null.
1631 * @param bundleName resource bundle name, may be null.
1632 * @param key key, may be null.
1633 * @param param0 Parameter to the log message.
1634 * @param param1 Parameter to the log message.
1635 * @param param2 Parameter to the log message.
1637 public static void logrb(final Logger logger,
1639 final String bundleName,
1641 final Object param0,
1642 final Object param1,
1643 final Object param2) {
1644 if (logger.isEnabledFor(level)) {
1645 forcedLog(logger, level,
1646 format(bundleName, key, toArray(param0, param1, param2)));
1652 * Log a parameterized message using a pattern from a resource bundle.
1653 * @param logger logger, may not be null.
1654 * @param level level, may not be null.
1655 * @param bundleName resource bundle name, may be null.
1656 * @param key key, may be null.
1657 * @param param0 Parameter to the log message.
1658 * @param param1 Parameter to the log message.
1659 * @param param2 Parameter to the log message.
1660 * @param param3 Parameter to the log message.
1662 public static void logrb(final Logger logger,
1664 final String bundleName,
1666 final Object param0,
1667 final Object param1,
1668 final Object param2,
1669 final Object param3) {
1670 if (logger.isEnabledFor(level)) {
1671 forcedLog(logger, level,
1672 format(bundleName, key,
1673 toArray(param0, param1, param2, param3)));