1 23 package com.sun.enterprise.tools.jsfext.util; 24 25 import com.sun.web.ui.util.MessageUtil; 26 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 30 31 51 public class LogUtil { 52 54 58 64 public static boolean finestEnabled() { 65 return getLogger().isLoggable(Level.FINEST); 66 } 67 68 77 public static boolean finestEnabled(Object loggerId) { 78 return getLogger(loggerId).isLoggable(Level.FINEST); 79 } 80 81 92 public static void finest(String msgId, Object param) { 93 finest(msgId, new Object [] {param}); 94 } 95 96 107 public static void finest(String msgId, Object [] params) { 108 getLogger().log(Level.FINEST, getMessage(msgId, params, false)); 109 } 110 111 125 public static void finest(Object loggerId, String msgId, Object param) { 126 finest(loggerId, msgId, new Object [] {param}); 127 } 128 129 143 public static void finest(Object loggerId, String msgId, Object [] params) { 144 getLogger(loggerId).log(Level.FINEST, getMessage(msgId, params, false)); 145 } 146 147 154 public static void finest(String msg) { 155 finest(DEFAULT_LOGGER, msg); 156 } 157 158 169 public static void finest(Object loggerId, String msg) { 170 getLogger(loggerId).log(Level.FINEST, getMessage(msg, false)); 171 } 172 173 181 public static void finest(String msg, Throwable ex) { 182 getLogger().log(Level.FINEST, 183 DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msg, ex); 184 } 185 186 197 public static void finest(Object loggerId, String msg, Throwable ex) { 198 getLogger(loggerId).log(Level.FINEST, 199 DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msg, ex); 200 } 201 202 203 207 213 public static boolean finerEnabled() { 214 return getLogger().isLoggable(Level.FINER); 215 } 216 217 226 public static boolean finerEnabled(Object loggerId) { 227 return getLogger(loggerId).isLoggable(Level.FINER); 228 } 229 230 241 public static void finer(String msgId, Object param) { 242 finer(msgId, new Object [] {param}); 243 } 244 245 256 public static void finer(String msgId, Object [] params) { 257 getLogger().log(Level.FINER, getMessage(msgId, params, false)); 258 } 259 260 274 public static void finer(Object loggerId, String msgId, Object param) { 275 finer(loggerId, msgId, new Object [] {param}); 276 } 277 278 292 public static void finer(Object loggerId, String msgId, Object [] params) { 293 getLogger(loggerId).log(Level.FINER, getMessage(msgId, params, false)); 294 } 295 296 303 public static void finer(String msg) { 304 finer(DEFAULT_LOGGER, msg); 305 } 306 307 318 public static void finer(Object loggerId, String msg) { 319 getLogger(loggerId).log(Level.FINER, getMessage(msg, false)); 320 } 321 322 330 public static void finer(String msg, Throwable ex) { 331 getLogger().log(Level.FINER, 332 DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msg, ex); 333 } 334 335 346 public static void finer(Object loggerId, String msg, Throwable ex) { 347 getLogger(loggerId).log(Level.FINER, 348 DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msg, ex); 349 } 350 351 352 356 362 public static boolean fineEnabled() { 363 return getLogger().isLoggable(Level.FINE); 364 } 365 366 375 public static boolean fineEnabled(Object loggerId) { 376 return getLogger(loggerId).isLoggable(Level.FINE); 377 } 378 379 390 public static void fine(String msgId, Object param) { 391 fine(msgId, new Object [] {param}); 392 } 393 394 405 public static void fine(String msgId, Object [] params) { 406 getLogger().log(Level.FINE, getMessage(msgId, params, false)); 407 } 408 409 423 public static void fine(Object loggerId, String msgId, Object param) { 424 fine(loggerId, msgId, new Object [] {param}); 425 } 426 427 441 public static void fine(Object loggerId, String msgId, Object [] params) { 442 getLogger(loggerId).log(Level.FINE, getMessage(msgId, params, false)); 443 } 444 445 452 public static void fine(String msg) { 453 fine(DEFAULT_LOGGER, msg); 454 } 455 456 467 public static void fine(Object loggerId, String msg) { 468 getLogger(loggerId).log(Level.FINE, getMessage(msg, false)); 469 } 470 471 478 public static void fine(String msg, Throwable ex) { 479 getLogger().log(Level.FINE, getMessage(msg, false), ex); 480 } 481 482 493 public static void fine(Object loggerId, String msg, Throwable ex) { 494 getLogger(loggerId).log(Level.FINE, getMessage(msg, false), ex); 495 } 496 497 498 502 508 public static boolean configEnabled() { 509 return getLogger().isLoggable(Level.CONFIG); 510 } 511 512 521 public static boolean configEnabled(Object loggerId) { 522 return getLogger(loggerId).isLoggable(Level.CONFIG); 523 } 524 525 536 public static void config(String msgId, Object param) { 537 config(msgId, new Object [] {param}); 538 } 539 540 551 public static void config(String msgId, Object [] params) { 552 getLogger().log(Level.CONFIG, getMessage(msgId, params, false)); 553 } 554 555 569 public static void config(Object loggerId, String msgId, Object param) { 570 config(loggerId, msgId, new Object [] {param}); 571 } 572 573 587 public static void config(Object loggerId, String msgId, Object [] params) { 588 getLogger(loggerId).log(Level.CONFIG, getMessage(msgId, params, false)); 589 } 590 591 598 public static void config(String msg) { 599 config(DEFAULT_LOGGER, msg); 600 } 601 602 613 public static void config(Object loggerId, String msg) { 614 getLogger(loggerId).log(Level.CONFIG, getMessage(msg, false)); 615 } 616 617 625 public static void config(String msg, Throwable ex) { 626 getLogger().log(Level.CONFIG, getMessage(msg, false), ex); 627 } 628 629 640 public static void config(Object loggerId, String msg, Throwable ex) { 641 getLogger(loggerId).log(Level.CONFIG, getMessage(msg, false), ex); 642 } 643 644 645 649 655 public static boolean infoEnabled() { 656 return getLogger().isLoggable(Level.INFO); 657 } 658 659 668 public static boolean infoEnabled(Object loggerId) { 669 return getLogger(loggerId).isLoggable(Level.INFO); 670 } 671 672 681 public static void info(String msgId) { 682 getLogger().log(Level.INFO, getMessage(msgId, true)); 683 } 684 685 697 public static void info(Object loggerId, String msgId) { 698 getLogger(loggerId).log(Level.INFO, getMessage(msgId, true)); 699 } 700 701 712 public static void info(String msgId, Object param) { 713 info(msgId, new Object [] {param}); 714 } 715 716 727 public static void info(String msgId, Object [] params) { 728 getLogger().log(Level.INFO, getMessage(msgId, params, true)); 729 } 730 731 745 public static void info(Object loggerId, String msgId, Object param) { 746 info(loggerId, msgId, new Object [] {param}); 747 } 748 749 763 public static void info(Object loggerId, String msgId, Object [] params) { 764 getLogger(loggerId).log(Level.INFO, getMessage(msgId, params, true)); 765 } 766 767 778 public static void info(String msgId, Throwable ex) { 779 getLogger().log(Level.INFO, getMessage(msgId, false), ex); 780 } 781 782 796 public static void info(Object loggerId, String msgId, Throwable ex) { 797 getLogger(loggerId).log(Level.INFO, getMessage(msgId, false), ex); 798 } 799 800 801 805 811 public static boolean warningEnabled() { 812 return getLogger().isLoggable(Level.WARNING); 813 } 814 815 824 public static boolean warningEnabled(Object loggerId) { 825 return getLogger(loggerId).isLoggable(Level.WARNING); 826 } 827 828 837 public static void warning(String msgId) { 838 getLogger().log(Level.WARNING, getMessage(msgId, true)); 839 } 840 841 853 public static void warning(Object loggerId, String msgId) { 854 getLogger(loggerId).log(Level.WARNING, getMessage(msgId, true)); 855 } 856 857 868 public static void warning(String msgId, Object param) { 869 warning(msgId, new Object [] {param}); 870 } 871 872 883 public static void warning(String msgId, Object [] params) { 884 getLogger().log(Level.WARNING, getMessage(msgId, params, true)); 885 } 886 887 901 public static void warning(Object loggerId, String msgId, Object param) { 902 warning(loggerId, msgId, new Object [] {param}); 903 } 904 905 919 public static void warning(Object loggerId, String msgId, Object [] params) { 920 getLogger(loggerId).log(Level.WARNING, getMessage(msgId, params, true)); 921 } 922 923 934 public static void warning(String msgId, Throwable ex) { 935 getLogger().log(Level.WARNING, getMessage(msgId, false), ex); 936 } 937 938 952 public static void warning(Object loggerId, String msgId, Throwable ex) { 953 getLogger(loggerId).log(Level.WARNING, getMessage(msgId, false), ex); 954 } 955 956 957 961 967 public static boolean severeEnabled() { 968 return getLogger().isLoggable(Level.SEVERE); 969 } 970 971 980 public static boolean severeEnabled(Object loggerId) { 981 return getLogger(loggerId).isLoggable(Level.SEVERE); 982 } 983 984 993 public static void severe(String msgId) { 994 getLogger().log(Level.SEVERE, getMessage(msgId, true)); 995 } 996 997 1009 public static void severe(Object loggerId, String msgId) { 1010 getLogger(loggerId).log(Level.SEVERE, getMessage(msgId, true)); 1011 } 1012 1013 1024 public static void severe(String msgId, Object param) { 1025 severe(msgId, new Object [] {param}); 1026 } 1027 1028 1039 public static void severe(String msgId, Object [] params) { 1040 getLogger().log(Level.SEVERE, getMessage(msgId, params, true)); 1041 } 1042 1043 1057 public static void severe(Object loggerId, String msgId, Object param) { 1058 severe(loggerId, msgId, new Object [] {param}); 1059 } 1060 1061 1075 public static void severe(Object loggerId, String msgId, Object [] params) { 1076 getLogger(loggerId).log(Level.SEVERE, getMessage(msgId, params, true)); 1077 } 1078 1079 1090 public static void severe(String msgId, Throwable ex) { 1091 getLogger().log(Level.SEVERE, getMessage(msgId, false), ex); 1092 } 1093 1094 1108 public static void severe(Object loggerId, String msgId, Throwable ex) { 1109 getLogger(loggerId).log(Level.SEVERE, getMessage(msgId, false), ex); 1110 } 1111 1112 1113 1117 1122 private static Logger getLogger() { 1123 return DEFAULT_LOGGER; 1124 } 1125 1126 1136 private static Logger getLogger(Object key) { 1137 if (key == null) { 1139 return getLogger(); 1140 } 1141 1142 if (key instanceof String ) { 1144 return getLogger((String ) key); 1145 } 1146 1147 if (key instanceof Logger ) { 1149 return (Logger ) key; 1150 } 1151 1152 if (key instanceof Class ) { 1154 return getLogger((Class ) key); 1155 } 1156 1157 return getLogger(key.getClass()); 1159 } 1160 1161 1168 private static Logger getLogger(String key) { 1169 if (key.trim().length() == 0) { 1170 return DEFAULT_LOGGER; 1171 } 1172 return Logger.getLogger(key); 1173 } 1174 1175 1182 private static Logger getLogger(Class key) { 1183 if (key == null) { 1184 return DEFAULT_LOGGER; 1185 } 1186 return Logger.getLogger(key.getName()); 1187 } 1188 1189 1201 private static String getMessage(String msgId, boolean strict) { 1202 return getMessage(msgId, new Object [0], strict); 1203 } 1204 1205 1218 private static String getMessage( 1219 String msgId, Object [] params, boolean strict) { 1220 String result = MessageUtil.getMessage(BUNDLE_NAME, msgId, params); 1221 if (result.equals(msgId)) { 1222 if (strict) { 1224 if (msgId.equals(KEY_NOT_FOUND_KEY)) { 1226 result = KEY_NOT_FOUND_KEY + LOG_KEY_MESSAGE_SEPARATOR 1228 + "'" + params[0] + "' not found in ResourceBundle: '" 1229 + BUNDLE_NAME + "'"; 1230 } else { 1231 result = getMessage( 1232 KEY_NOT_FOUND_KEY, new Object [] {msgId}, strict); 1233 } 1234 } else { 1235 result = DEFAULT_LOG_KEY + LOG_KEY_MESSAGE_SEPARATOR + msgId; 1237 } 1238 } else { 1239 result = msgId + LOG_KEY_MESSAGE_SEPARATOR + result; 1241 } 1242 1243 return result; 1245 } 1246 1247 1251 public static final String BUNDLE_NAME = 1252 "com.sun.enterprise.tools.jsfext.resource.LogMessages"; 1253 1254 1257 public static final String DEFAULT_LOG_KEY = "WEBUI0001"; 1258 1259 1262 public static final String DEFAULT_LOGGER_NAME = 1263 "com.sun.enterprise.tools.jsfext"; 1264 1265 1269 public static final String KEY_NOT_FOUND_KEY = "WEBUI0002"; 1270 1271 1272 1275 private static final Logger DEFAULT_LOGGER = getLogger(DEFAULT_LOGGER_NAME); 1276 1277 1280 private static final String LOG_KEY_MESSAGE_SEPARATOR = ": "; 1281 1282} 1283 | Popular Tags |