From b21ad6f2aafa854c671719a99b7e97b47ba5f43c Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Tue, 9 Oct 2012 03:22:02 +0000 Subject: [PATCH] ICU-9268 Deleting ICULogger. Replace ICULogger with the stock Java Logger in TimeZone class. X-SVN-Rev: 32568 --- .../core/src/com/ibm/icu/impl/ICULogger.java | 190 ------------------ .../core/src/com/ibm/icu/util/TimeZone.java | 15 +- 2 files changed, 4 insertions(+), 201 deletions(-) delete mode 100644 icu4j/main/classes/core/src/com/ibm/icu/impl/ICULogger.java diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICULogger.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICULogger.java deleted file mode 100644 index 4ccd8067421..00000000000 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICULogger.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2009-2010, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ -package com.ibm.icu.impl; - -import java.util.logging.ConsoleHandler; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * Extends the Java Logger class adding a method to turn off/on logging. - * Classes where logging is wanted contains a static ICULogger object - * with logging turned off by default unless the system property - * "icu4j.debug.logging" is set to "all" - * - * If "icu4j.debug.logging" is not set to "all", then the individual loggers needs - * to be turned on manually. (e.g. TimeZone.TimeZoneLogger.turnLoggingOn()) - *

- * To use logging, the system property "icu4j.debug.logging" must be set to "on" or "all", - * otherwise the static ICULogger object will be null. This will help lower any unneccessary - * resource usage when logging is not desired. - *

- * Examples:

- * Usage in code - *

- *
- * public class Class {
- *     // Create logger object (usually with the class name)
- *     public static ICULogger ClassLogger = ICULogger.getICULogger(Class.class.getName());
- *     
- *     // Method that will use logger.
- *     public boolean hasSomething(Object obj) {
- *         if (obj == null) {
- *              // Log that obj is null.
- *              // Note: Good to check for null and if logging is turned on to minimize resource usage when logging is not needed.
- *              if (ClassLogger != null && ClassLogger.isLoggingOn()) {
- *                  ClassLogger.warning("obj is null so false was returned by default.");
- *              }
- *             return false;
- *         }
- *         
- *         ...
- *         
- *     }
- * }
- * 
- *
- * Turning on logging (using the default settings) - *
- *
- * java -Dicu4j.debug.logging=all program
- * 
- *
- */ - -public class ICULogger extends Logger { - private static enum LOGGER_STATUS { ON, OFF, NULL }; - private static final String GLOBAL_FLAG_TURN_ON_LOGGING = "all"; - private static final String SYSTEM_PROP_LOGGER = "icu4j.debug.logging"; - - private LOGGER_STATUS currentStatus; - - /** - * ICULogger constructor that calls the parent constructor with the desired parameters. - */ - private ICULogger(String name, String resourceBundleName) { - super(name, resourceBundleName); - } - - /** - * Set the status to either on or off. Set the level of the logger to INFO. - */ - private void setStatus(LOGGER_STATUS newStatus) { - if (currentStatus != newStatus) { - /* Default to level INFO */ - if (currentStatus == LOGGER_STATUS.OFF && newStatus == LOGGER_STATUS.ON) { - this.setLevel(Level.INFO); - } - - currentStatus = newStatus; - - if (currentStatus == LOGGER_STATUS.OFF){ - this.setLevel(Level.OFF); - } - } - } - - /** - * Check the system property SYSTEM_PROP_LOGGER to see if it is set. - * return true if it is otherwise return false. - */ - private static LOGGER_STATUS checkGlobalLoggingFlag() { - try { - String prop = System.getProperty(SYSTEM_PROP_LOGGER); - - if (prop != null) { - if (prop.equals(GLOBAL_FLAG_TURN_ON_LOGGING)) { - return LOGGER_STATUS.ON; - } - return LOGGER_STATUS.OFF; - } - } catch (SecurityException e) { - // Ignore the security exception and fall-through - } - - return LOGGER_STATUS.NULL; - } - - /** - * Instantiates a new ICULogger object with logging turned off by default. - * - * @param name to be use by the logger (usually is the class name) - * @return a new ICULogger object - * @draft ICU 4.4 - * @provisional This API might change or be removed in a future release. - */ - public static ICULogger getICULogger(String name) { - return getICULogger(name, null); - } - - /** - * Instantiates a new ICULogger object with logging turned off by default - * unless the system property "icu4j.debug.logging" is set to "all" - * - * @param name to be use by the logger (usually is the class name) - * @param resourceBundleName name to localize messages (can be null) - * @return a new ICULogger object - * @draft ICU 4.4 - * @provisional This API might change or be removed in a future release. - */ - public static ICULogger getICULogger(String name, String resourceBundleName) { - LOGGER_STATUS flag = checkGlobalLoggingFlag(); - if (flag != LOGGER_STATUS.NULL) { - ICULogger logger = new ICULogger(name, resourceBundleName); - - /* Add a default handler to logger*/ - logger.addHandler(new ConsoleHandler()); - - /* Turn off logging by default unless SYSTEM_PROP_LOGGER property is set to "all" */ - if (flag == LOGGER_STATUS.ON) { - logger.turnOnLogging(); - } else { - logger.turnOffLogging(); - } - - return logger; - } - return null; - } - - /** - * Determined if logging is turned on or off. The return value is true if logging is on. - * - * @return whether logging is turned on or off. - * @draft ICU 4.4 - * @provisional This API might change or be removed in a future release. - */ - public boolean isLoggingOn() { - if (currentStatus == LOGGER_STATUS.ON) { - return true; - } else { - return false; - } - } - - /** - * Turn logging on. - * - * @draft ICU 4.4 - * @provisional This API might change or be removed in a future release. - */ - public void turnOnLogging() { - setStatus(LOGGER_STATUS.ON); - } - - /** - * Turn logging off. - * - * @draft ICU 4.4 - * @provisional This API might change or be removed in a future release. - */ - public void turnOffLogging() { - setStatus(LOGGER_STATUS.OFF); - } - -} diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java index 19f1b9d72cf..fc0414145c3 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java @@ -12,10 +12,10 @@ import java.util.Date; import java.util.Locale; import java.util.MissingResourceException; import java.util.Set; +import java.util.logging.Logger; import com.ibm.icu.impl.Grego; import com.ibm.icu.impl.ICUConfig; -import com.ibm.icu.impl.ICULogger; import com.ibm.icu.impl.JavaTimeZone; import com.ibm.icu.impl.TimeZoneAdapter; import com.ibm.icu.impl.ZoneMeta; @@ -112,12 +112,9 @@ import com.ibm.icu.util.ULocale.Category; */ abstract public class TimeZone implements Serializable, Cloneable, Freezable { /** - * {@icu} A logger for TimeZone. Will be null if logging is not on by way of system - * property: "icu4j.debug.logging" - * @draft ICU 4.4 - * @provisional This API might change or be removed in a future release. + * Logger instance for this class */ - public static ICULogger TimeZoneLogger = ICULogger.getICULogger(TimeZone.class.getName()); + private static final Logger LOGGER = Logger.getLogger("com.ibm.icu.util.TimeZone"); // using serialver from jdk1.4.2_05 private static final long serialVersionUID = -744942128318337471L; @@ -775,11 +772,7 @@ abstract public class TimeZone implements Serializable, Cloneable, Freezable