harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r449286 - in /incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging: LogManager.java Logger.java
Date Sat, 23 Sep 2006 18:47:23 GMT
Author: ndbeyer
Date: Sat Sep 23 11:47:23 2006
New Revision: 449286

URL: http://svn.apache.org/viewvc?view=rev&rev=449286
Log:
Rework Logger and LogManager:
* Setup root and global Loggers manually, instead of use factory methods.
* Return LogManager static initialization to call public 'readConfiguration'
* Cleanup readConfiguration implementation

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java?view=diff&rev=449286&r1=449285&r2=449286
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
Sat Sep 23 11:47:23 2006
@@ -191,17 +191,17 @@
 
 				// read configuration
 				try {
-					manager.readConfigurationImpl(true);
+					manager.readConfiguration();
 				} catch (Exception e) {
 					e.printStackTrace();
 				}
 
 				// if global logger has been initialized, set root as its parent
-                Logger root = Logger.getLogger(""); //$NON-NLS-1$
+                Logger root = new Logger("", null); //$NON-NLS-1$
+                Logger.global.setParent(root);
                 
-                Logger global = (Logger.global == null ? Logger.getLogger("global") : Logger.global);
-                global.setParent(root);
-
+                manager.addLogger(root);
+                manager.addLogger(Logger.global);
                 return null;
 			}
 		});
@@ -219,9 +219,10 @@
         listeners = new PropertyChangeSupport(this);
         // add shutdown hook to ensure that the associated resource will be
         // freed when JVM exits
-        AccessController.doPrivileged(new PrivilegedAction<Object>() {
-            public Object run() {
+        AccessController.doPrivileged(new PrivilegedAction<Void>() {
+            public Void run() {
                 Runtime.getRuntime().addShutdownHook(new Thread() {
+                    @Override
                     public void run() {
                         reset();
                     }
@@ -377,7 +378,7 @@
      *             not have the required permissions to perform this action
      */
     public void readConfiguration() throws IOException {
-        readConfigurationImpl(false);
+        readConfigurationImpl();
     }
 
     // use privilege code to get system property
@@ -403,7 +404,7 @@
     }
 
     // actual default initialization process
-    private synchronized void readConfigurationImpl(boolean createLoggers) throws IOException
{
+    private synchronized void readConfigurationImpl() throws IOException {
         checkAccess();
         boolean needInit = true;
 
@@ -429,7 +430,7 @@
             InputStream input = null;
             try {
                 input = new BufferedInputStream(new FileInputStream(configFile));
-                readConfigurationImpl(input, createLoggers);
+                readConfigurationImpl(input);
             } finally {
                 try {
                     input.close();
@@ -440,7 +441,7 @@
     }
 
     // actual initialization process from a given input stream
-    private synchronized void readConfigurationImpl(InputStream ins, boolean createLoggers)
+    private synchronized void readConfigurationImpl(InputStream ins)
             throws IOException {
         reset();
         props.load(ins);
@@ -449,12 +450,12 @@
         parseConfigProp();
 
         // set levels for logger
-        initLoggers(createLoggers);
+        initLoggers();
         listeners.firePropertyChange(null, null, null);
     }
 
     // init "level" properties for all registered loggers
-    private void initLoggers(boolean createLoggers) {
+    private void initLoggers() {
         Enumeration<?> enumeration = props.propertyNames();
         while (enumeration.hasMoreElements()) {
             // search for all properties whose name is ended with ".level"
@@ -465,10 +466,8 @@
                 Logger l = loggers.get(loggerName);
                 if (null != l) {
                     l.setManager(this);
-                } else if (createLoggers) {
-                    Logger.getLogger(loggerName);
                 }
-            }else if(createLoggers && property.endsWith(".handlers")){ //$NON-NLS-1$
+            }else if(property.endsWith(".handlers")){ //$NON-NLS-1$
                 String loggerName = property.substring(0,
                         property.length() - ".handlers".length()); //$NON-NLS-1$
                 Logger.getLogger(loggerName);
@@ -506,7 +505,7 @@
      */
     public void readConfiguration(InputStream ins) throws IOException {
         checkAccess();
-        readConfigurationImpl(ins, false);
+        readConfigurationImpl(ins);
     }
 
     /**
@@ -526,7 +525,7 @@
         props.clear();
         Iterator<Logger> it = loggers.values().iterator();
         while (it.hasNext()) {
-            Logger l = (Logger) it.next();
+            Logger l = it.next();
             l.reset();
         }
         Logger root = loggers.get(""); //$NON-NLS-1$

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java?view=diff&rev=449286&r1=449285&r2=449286
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
Sat Sep 23 11:47:23 2006
@@ -13,7 +13,6 @@
  * limitations under the License.
  */
 
-
 package java.util.logging;
 
 import java.security.AccessController;
@@ -73,39 +72,10 @@
  */
 public class Logger {
 
-    /*
-     * -------------------------------------------------------------------
-     * Constants
-     * -------------------------------------------------------------------
-     */
-
-    // message of "entering" series methods
-    private final static String MSG_ENTERING = "ENTRY"; //$NON-NLS-1$
-
-    // message of "exiting" series methods
-    private final static String MSG_EXITING = "RETURN"; //$NON-NLS-1$
-
-    // message of "throwing" series methods
-    private final static String MSG_THROWING = "THROW"; //$NON-NLS-1$
-
-    private final static int OFF_VALUE = Level.OFF.intValue();
-
-    /*
-     * --------------------------------------------------------------------
-     * Class variables
-     * --------------------------------------------------------------------
-     */
-
     /**
      * The global logger is provided as convenience for casual use.
      */
-    public final static Logger global = Logger.getLogger("global"); //$NON-NLS-1$
-
-    /*
-     * -------------------------------------------------------------------
-     * Instance variables
-     * -------------------------------------------------------------------
-     */
+    public final static Logger global = new Logger("global", null); //$NON-NLS-1$
 
     // the name of this logger
     private volatile String name;
@@ -129,7 +99,7 @@
     private ResourceBundle resBundle;
 
     // the handlers attached to this logger
-    private List<Handler> handlers = null;
+    private List<Handler> handlers;
 
     /*
      * flag indicating whether to notify parent's handlers on receiving a log
@@ -142,9 +112,9 @@
 
     private List<Logger> childs;
     
-    private LogManager manager = null;
+    private LogManager manager;
 
-    private boolean handlerInited = false;
+    private boolean handlerInited;
 
     /*
      * -------------------------------------------------------------------
@@ -675,12 +645,11 @@
      */
     private boolean internalIsLoggable(Level l) {
         int effectiveLevel = levelIntVal;
-        if (effectiveLevel == OFF_VALUE) {
+        if (effectiveLevel == Level.OFF.intValue()) {
             // always return false if the effective level is off
             return false;
-        } else {
-            return l.intValue() >= effectiveLevel;
         }
+        return l.intValue() >= effectiveLevel;
     }
 
     /**
@@ -739,7 +708,7 @@
      */
     public void entering(String sourceClass, String sourceMethod) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, MSG_ENTERING);
+            LogRecord record = new LogRecord(Level.FINER, "ENTRY");
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);
@@ -763,7 +732,7 @@
      */
     public void entering(String sourceClass, String sourceMethod, Object param) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, MSG_ENTERING + " {0}"); //$NON-NLS-1$
+            LogRecord record = new LogRecord(Level.FINER, "ENTRY" + " {0}"); //$NON-NLS-1$
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);
@@ -789,9 +758,9 @@
     public void entering(String sourceClass, String sourceMethod,
             Object[] params) {
         if (internalIsLoggable(Level.FINER)) {
-        	String msg = MSG_ENTERING;
+        	String msg = "ENTRY";
 			if (null != params) {
-				StringBuffer msgBuffer = new StringBuffer(MSG_ENTERING);
+				StringBuffer msgBuffer = new StringBuffer("ENTRY");
 				for (int i = 0; i < params.length; i++) {
 					msgBuffer.append(" {" + i + "}"); //$NON-NLS-1$ //$NON-NLS-2$
 				}
@@ -819,7 +788,7 @@
      */
     public void exiting(String sourceClass, String sourceMethod) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, MSG_EXITING);
+            LogRecord record = new LogRecord(Level.FINER, "RETURN");
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);
@@ -843,7 +812,7 @@
      */
     public void exiting(String sourceClass, String sourceMethod, Object result) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, MSG_EXITING + " {0}"); //$NON-NLS-1$
+            LogRecord record = new LogRecord(Level.FINER, "RETURN" + " {0}"); //$NON-NLS-1$
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);
@@ -869,7 +838,7 @@
     public void throwing(String sourceClass, String sourceMethod,
             Throwable thrown) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, MSG_THROWING);
+            LogRecord record = new LogRecord(Level.FINER, "THROW");
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);



Mime
View raw message