[kaffe] CVS kaffe (robilad): resynced with GNU Classpath: logging fix

Kaffe CVS cvs-commits at kaffe.org
Sat Feb 19 07:46:41 PST 2005


PatchSet 5563 
Date: 2005/02/19 15:42:11
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
resynced with GNU Classpath: logging fix

2005-02-19  Dalibor Topic  <robilad at kaffe.org>

Resynced with GNU Classpath.

2005-02-16  Sven de Marothy  <sven at physto.se>

* java/util/logging/LogManager.java
Reformatted.
        (readConfiguration): If a logger for a key is not found, create one.

Members: 
	ChangeLog:1.3607->1.3608 
	libraries/javalib/java/util/logging/LogManager.java:1.9->1.10 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3607 kaffe/ChangeLog:1.3608
--- kaffe/ChangeLog:1.3607	Sat Feb 19 15:30:20 2005
+++ kaffe/ChangeLog	Sat Feb 19 15:42:11 2005
@@ -2,6 +2,16 @@
 
 	Resynced with GNU Classpath.
 	
+	2005-02-16  Sven de Marothy  <sven at physto.se>
+
+	* java/util/logging/LogManager.java 
+	Reformatted.
+        (readConfiguration): If a logger for a key is not found, create one.
+	
+2005-02-19  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+	
 	2005-02-16  Michael Koch  <konqueror at gmx.de>
 
 	* gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java,
Index: kaffe/libraries/javalib/java/util/logging/LogManager.java
diff -u kaffe/libraries/javalib/java/util/logging/LogManager.java:1.9 kaffe/libraries/javalib/java/util/logging/LogManager.java:1.10
--- kaffe/libraries/javalib/java/util/logging/LogManager.java:1.9	Sat Oct 23 10:40:49 2004
+++ kaffe/libraries/javalib/java/util/logging/LogManager.java	Sat Feb 19 15:42:13 2005
@@ -103,17 +103,14 @@
    * The singleton LogManager instance.
    */
   private static LogManager logManager;
-  
 
   /**
    * The registered named loggers; maps the name of a Logger to
    * a WeakReference to it.
    */
   private Map loggers;
-
   final Logger rootLogger;
 
-
   /**
    * The properties for the logging framework which have been
    * read in last.
@@ -132,20 +129,19 @@
    * behave differently from the reference implementation in
    * this case.
    */
-  private final PropertyChangeSupport pcs
-    = new PropertyChangeSupport(/* source bean */ LogManager.class);
+  private final PropertyChangeSupport pcs = new PropertyChangeSupport( /* source bean */
+  LogManager.class);
 
   protected LogManager()
   {
     if (logManager != null)
-      throw new IllegalStateException(
-        "there can be only one LogManager; use LogManager.getLogManager()");
+      throw new IllegalStateException("there can be only one LogManager; use LogManager.getLogManager()");
 
     logManager = this;
     loggers = new java.util.HashMap();
     rootLogger = new Logger("", null);
     addLogger(rootLogger);
-    
+
     /* Make sure that Logger.global has the rootLogger as its parent.
      *
      * Logger.global is set during class initialization of Logger,
@@ -166,7 +162,6 @@
     Logger.getLogger("global").setUseParentHandlers(true);
   }
 
-
   /**
    * Returns the globally shared LogManager instance.
    */
@@ -176,32 +171,30 @@
   }
 
   static
-  {
-    makeLogManager();
-    
-    /* The Javadoc description of the class explains
-     * what is going on here.
-     */
-    Object configurator = createInstance(
-      System.getProperty("java.util.logging.config.class"),
-      /* must be instance of */ Object.class);
-
-    try
-    {
-      if (configurator == null)
-        getLogManager().readConfiguration();
-    }
-    catch (IOException ex)
     {
-      /* FIXME: Is it ok to ignore exceptions here? */
+      makeLogManager();
+
+      /* The Javadoc description of the class explains
+       * what is going on here.
+       */
+      Object configurator = createInstance(System.getProperty("java.util.logging.config.class"),
+                                           /* must be instance of */ Object.class);
+
+      try
+        {
+	  if (configurator == null)
+	    getLogManager().readConfiguration();
+        }
+      catch (IOException ex)
+        {
+	  /* FIXME: Is it ok to ignore exceptions here? */
+        }
     }
-  }
-  
 
   private static LogManager makeLogManager()
   {
-    String      managerClassName;
-    LogManager  manager;
+    String managerClassName;
+    LogManager manager;
 
     managerClassName = System.getProperty("java.util.logging.manager");
     manager = (LogManager) createInstance(managerClassName, LogManager.class);
@@ -210,12 +203,11 @@
 
     if (managerClassName != null)
       System.err.println("WARNING: System property \"java.util.logging.manager\""
-			 + " should be the name of a subclass of java.util.logging.LogManager");
+                         + " should be the name of a subclass of java.util.logging.LogManager");
 
     return new LogManager();
   }
 
-
   /**
    * Registers a listener which will be notified when the
    * logging properties are re-read.
@@ -228,7 +220,6 @@
     pcs.addPropertyChangeListener(listener);
   }
 
-
   /**
    * Unregisters a listener.
    *
@@ -242,7 +233,6 @@
       pcs.removePropertyChangeListener(listener);
   }
 
-
   /**
    * Adds a named logger.  If a logger with the same name has
    * already been registered, the method returns <code>false</code>
@@ -271,9 +261,8 @@
      * that LogManager does its synchronization on the globally
      * shared instance of LogManager.
      */
-
     String name;
-    WeakReference  ref;
+    WeakReference ref;
 
     /* This will throw a NullPointerException if logger is null,
      * as required by the API specification.
@@ -282,18 +271,18 @@
 
     ref = (WeakReference) loggers.get(name);
     if (ref != null)
-    {
-      if (ref.get() != null)
-	return false;
+      {
+	if (ref.get() != null)
+	  return false;
 
-      /* There has been a logger under this name in the past,
-       * but it has been garbage collected.
-       */
-      loggers.remove(ref);
-    }
+	/* There has been a logger under this name in the past,
+	 * but it has been garbage collected.
+	 */
+	loggers.remove(ref);
+      }
 
     /* Adding a named logger requires a security permission. */
-    if ((name != null) && !name.equals(""))
+    if ((name != null) && ! name.equals(""))
       checkAccess();
 
     Logger parent = findAncestor(logger);
@@ -308,27 +297,28 @@
      * its parent to "foo.bar".
      */
     if (parent != rootLogger)
-    {
-      for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();)
       {
-        Logger possChild = (Logger) ((WeakReference) loggers.get(iter.next())).get();
-        if ((possChild == null) || (possChild == logger) || (possChild.getParent() != parent))
-	  continue;
+	for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();)
+	  {
+	    Logger possChild = (Logger) ((WeakReference) loggers.get(iter.next()))
+	                       .get();
+	    if ((possChild == null) || (possChild == logger)
+	        || (possChild.getParent() != parent))
+	      continue;
 
-	if (!possChild.getName().startsWith(name))
-	  continue;
+	    if (! possChild.getName().startsWith(name))
+	      continue;
 
-	if (possChild.getName().charAt(name.length()) != '.')
-	  continue;
+	    if (possChild.getName().charAt(name.length()) != '.')
+	      continue;
 
-	possChild.setParent(logger);
+	    possChild.setParent(logger);
+	  }
       }
-    }
 
     return true;
   }
 
-
   /**
    * Finds the closest ancestor for a logger among the currently
    * registered ones.  For example, if the currently registered
@@ -348,40 +338,39 @@
   private synchronized Logger findAncestor(Logger child)
   {
     String childName = child.getName();
-    int    childNameLength = childName.length();
+    int childNameLength = childName.length();
     Logger best = rootLogger;
-    int    bestNameLength = 0;
+    int bestNameLength = 0;
 
-    Logger  cand;
-    String  candName;
-    int     candNameLength;
+    Logger cand;
+    String candName;
+    int candNameLength;
 
     if (child == rootLogger)
       return null;
 
     for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();)
-    {
-      candName = (String) iter.next();
-      candNameLength = candName.length();
-
-      if (candNameLength > bestNameLength
-	  && childNameLength > candNameLength
-	  && childName.startsWith(candName)
-	  && childName.charAt(candNameLength) == '.')
       {
-        cand = (Logger) ((WeakReference) loggers.get(candName)).get();
-	if ((cand == null) || (cand == child))
-	  continue;
+	candName = (String) iter.next();
+	candNameLength = candName.length();
+
+	if (candNameLength > bestNameLength
+	    && childNameLength > candNameLength
+	    && childName.startsWith(candName)
+	    && childName.charAt(candNameLength) == '.')
+	  {
+	    cand = (Logger) ((WeakReference) loggers.get(candName)).get();
+	    if ((cand == null) || (cand == child))
+	      continue;
 
-	bestNameLength = candName.length();
-	best = cand;
+	    bestNameLength = candName.length();
+	    best = cand;
+	  }
       }
-    }
 
     return best;
   }
 
-
   /**
    * Returns a Logger given its name.
    *
@@ -395,7 +384,7 @@
    */
   public synchronized Logger getLogger(String name)
   {
-    WeakReference  ref;
+    WeakReference ref;
 
     /* Throw a NullPointerException if name is null. */
     name.getClass();
@@ -407,7 +396,6 @@
       return null;
   }
 
-
   /**
    * Returns an Enumeration of currently registered Logger names.
    * Since other threads can register loggers at any time, the
@@ -421,7 +409,6 @@
     return Collections.enumeration(loggers.keySet());
   }
 
-
   /**
    * Resets the logging configuration by removing all handlers for
    * registered named loggers and setting their level to <code>null</code>.
@@ -431,8 +418,7 @@
    *         the caller is not granted the permission to control
    *         the logging infrastructure.
    */
-  public synchronized void reset()
-    throws SecurityException
+  public synchronized void reset() throws SecurityException
   {
     /* Throw a SecurityException if the caller does not have the
      * permission to control the logging infrastructure.
@@ -443,26 +429,25 @@
 
     Iterator iter = loggers.values().iterator();
     while (iter.hasNext())
-    {
-      WeakReference  ref;
-      Logger         logger;
-
-      ref = (WeakReference) iter.next();
-      if (ref != null)
       {
-	logger = (Logger) ref.get();
+	WeakReference ref;
+	Logger logger;
 
-	if (logger == null)
-	  iter.remove();
-	else if (logger != rootLogger)
-	  logger.setLevel(null);
+	ref = (WeakReference) iter.next();
+	if (ref != null)
+	  {
+	    logger = (Logger) ref.get();
+
+	    if (logger == null)
+	      iter.remove();
+	    else if (logger != rootLogger)
+	      logger.setLevel(null);
+	  }
       }
-    }
 
     rootLogger.setLevel(Level.INFO);
   }
 
-
   /**
    * Configures the logging framework by reading a configuration file.
    * The name and location of this file are specified by the system
@@ -488,97 +473,99 @@
   public synchronized void readConfiguration()
     throws IOException, SecurityException
   {
-    String       path;
-    InputStream  inputStream;
+    String path;
+    InputStream inputStream;
 
     path = System.getProperty("java.util.logging.config.file");
     if ((path == null) || (path.length() == 0))
-    {
-      String url = (System.getProperty("gnu.classpath.home.url")
-		    + "/logging.properties");
-      inputStream = new URL(url).openStream();
-    }
+      {
+	String url = (System.getProperty("gnu.classpath.home.url")
+	             + "/logging.properties");
+	inputStream = new URL(url).openStream();
+      }
     else
-    {
       inputStream = new java.io.FileInputStream(path);
-    }
 
     try
-    {
-      readConfiguration(inputStream);
-    }
+      {
+	readConfiguration(inputStream);
+      }
     finally
-    {
-      /* Close the stream in order to save
-       * resources such as file descriptors.
-       */
-      inputStream.close();
-    }
+      {
+	/* Close the stream in order to save
+	 * resources such as file descriptors.
+	 */
+	inputStream.close();
+      }
   }
 
-
   public synchronized void readConfiguration(InputStream inputStream)
     throws IOException, SecurityException
-  {	
-    Properties   newProperties;
-    Enumeration  keys;
+  {
+    Properties newProperties;
+    Enumeration keys;
 
     checkAccess();
     newProperties = new Properties();
     newProperties.load(inputStream);
-    this.properties = newProperties;    
+    this.properties = newProperties;
     keys = newProperties.propertyNames();
 
     while (keys.hasMoreElements())
-    {
-      String key = ((String) keys.nextElement()).trim();
-      String value = newProperties.getProperty(key);
-  
-      if (value == null)
-	continue;
-	
-	  value = value.trim();
-	
-	  if("handlers".equals(key))
-        {
-          StringTokenizer tokenizer = new StringTokenizer(value);
-          while(tokenizer.hasMoreTokens())
-            {
-              String handlerName = tokenizer.nextToken();	
-              try
-                {
-              	  Class handlerClass = Class.forName(handlerName);
-              	  getLogger("").addHandler((Handler)handlerClass.newInstance()); 
-                }
-              catch (ClassCastException ex)
-                {
-                  System.err.println("[LogManager] class " + handlerName + " is not subclass of java.util.logging.Handler");
-                }
-              catch (Exception ex)
-                {
-                  //System.out.println("[LogManager.readConfiguration]"+ex);
-                }
-            }
-        }
-	  
-      if (key.endsWith(".level"))
       {
-	String loggerName = key.substring(0, key.length() - 6);
-	Logger logger = getLogger(loggerName);
-	if (logger != null)
-	{
-	  try
+	String key = ((String) keys.nextElement()).trim();
+	String value = newProperties.getProperty(key);
+
+	if (value == null)
+	  continue;
+
+	value = value.trim();
+
+	if ("handlers".equals(key))
 	  {
-	    logger.setLevel(Level.parse(value));
+	    StringTokenizer tokenizer = new StringTokenizer(value);
+	    while (tokenizer.hasMoreTokens())
+	      {
+		String handlerName = tokenizer.nextToken();
+		try
+		  {
+		    Class handlerClass = Class.forName(handlerName);
+		    getLogger("").addHandler((Handler) handlerClass
+		                             .newInstance());
+		  }
+		catch (ClassCastException ex)
+		  {
+		    System.err.println("[LogManager] class " + handlerName
+		                       + " is not subclass of java.util.logging.Handler");
+		  }
+		catch (Exception ex)
+		  {
+		    //System.out.println("[LogManager.readConfiguration]"+ex);
+		  }
+	      }
 	  }
-	  catch (Exception _)
+
+	if (key.endsWith(".level"))
 	  {
-        //System.out.println("[LogManager.readConfiguration] "+_);
+	    String loggerName = key.substring(0, key.length() - 6);
+	    Logger logger = getLogger(loggerName);
+
+	    if (logger == null)
+	      {
+		logger = Logger.getLogger(loggerName);
+		addLogger(logger);
+	      }
+	    try
+	      {
+		logger.setLevel(Level.parse(value));
+	      }
+	    catch (Exception _)
+	      {
+		//System.out.println("[LogManager.readConfiguration] "+_);
+	      }
+	    continue;
 	  }
-	  continue;
-	}
       }
-    }
 
     /* The API specification does not talk about the
      * property name that is distributed with the
@@ -589,7 +576,6 @@
     pcs.firePropertyChange(null, null, null);
   }
 
-  
   /**
    * Returns the value of a configuration property as a String.
    */
@@ -601,7 +587,6 @@
       return null;
   }
 
-
   /**
    * Returns the value of a configuration property as an integer.
    * This function is a helper used by the Classpath implementation
@@ -617,16 +602,15 @@
   static int getIntProperty(String name, int defaultValue)
   {
     try
-    {
-      return Integer.parseInt(getLogManager().getProperty(name));
-    }
+      {
+	return Integer.parseInt(getLogManager().getProperty(name));
+      }
     catch (Exception ex)
-    {
-      return defaultValue;
-    }
+      {
+	return defaultValue;
+      }
   }
 
-
   /**
    * Returns the value of a configuration property as an integer,
    * provided it is inside the acceptable range.
@@ -646,7 +630,7 @@
    *        or if it is greater than the maximum value.
    */
   static int getIntPropertyClamped(String name, int defaultValue,
-				   int minValue, int maxValue)
+                                   int minValue, int maxValue)
   {
     int val = getIntProperty(name, defaultValue);
     if ((val < minValue) || (val > maxValue))
@@ -654,7 +638,6 @@
     return val;
   }
 
-
   /**
    * Returns the value of a configuration property as a boolean.
    * This function is a helper used by the Classpath implementation
@@ -670,17 +653,15 @@
   static boolean getBooleanProperty(String name, boolean defaultValue)
   {
     try
-    {
-      return (new Boolean(getLogManager().getProperty(name)))
-        .booleanValue();
-    }
+      {
+	return (new Boolean(getLogManager().getProperty(name))).booleanValue();
+      }
     catch (Exception ex)
-    {
-      return defaultValue;
-    }
+      {
+	return defaultValue;
+      }
   }
 
-
   /**
    * Returns the value of a configuration property as a Level.
    * This function is a helper used by the Classpath implementation
@@ -697,16 +678,15 @@
   static Level getLevelProperty(String propertyName, Level defaultValue)
   {
     try
-    {
-      return Level.parse(getLogManager().getProperty(propertyName));
-    }
+      {
+	return Level.parse(getLogManager().getProperty(propertyName));
+      }
     catch (Exception ex)
-    {
-      return defaultValue;
-    }
+      {
+	return defaultValue;
+      }
   }
 
-
   /**
    * Returns the value of a configuration property as a Class.
    * This function is a helper used by the Classpath implementation
@@ -724,64 +704,60 @@
     Class usingClass = null;
 
     try
-    {
-      String propertyValue = logManager.getProperty(propertyName);
-      if (propertyValue != null)
-        usingClass = Class.forName(propertyValue);
-      if (usingClass != null)
-        return usingClass;
-    }
+      {
+	String propertyValue = logManager.getProperty(propertyName);
+	if (propertyValue != null)
+	  usingClass = Class.forName(propertyValue);
+	if (usingClass != null)
+	  return usingClass;
+      }
     catch (Exception _)
-    {
-    }
+      {
+      }
 
     return defaultValue;
   }
 
-
-  static final Object getInstanceProperty(String propertyName,
-					  Class ofClass,
-					  Class defaultClass)
+  static final Object getInstanceProperty(String propertyName, Class ofClass,
+                                          Class defaultClass)
   {
     Class klass = getClassProperty(propertyName, defaultClass);
     if (klass == null)
       return null;
 
     try
-    {
-      Object obj = klass.newInstance();
-      if (ofClass.isInstance(obj))
-	return obj;
-    }
+      {
+	Object obj = klass.newInstance();
+	if (ofClass.isInstance(obj))
+	  return obj;
+      }
     catch (Exception _)
-    {
-    }
+      {
+      }
 
     if (defaultClass == null)
       return null;
 
     try
-    {
-      return defaultClass.newInstance();
-    }
+      {
+	return defaultClass.newInstance();
+      }
     catch (java.lang.InstantiationException ex)
-    {
-      throw new RuntimeException(ex.getMessage());
-    }
+      {
+	throw new RuntimeException(ex.getMessage());
+      }
     catch (java.lang.IllegalAccessException ex)
-    {
-      throw new RuntimeException(ex.getMessage());
-    }
+      {
+	throw new RuntimeException(ex.getMessage());
+      }
   }
 
-
   /**
    * An instance of <code>LoggingPermission("control")</code>
    * that is shared between calls to <code>checkAccess()</code>.
    */
-  private static final LoggingPermission controlPermission
-    = new LoggingPermission("control", null);
-
+  private static final LoggingPermission controlPermission = new LoggingPermission("control",
+                                                                                   null);
 
   /**
    * Checks whether the current security context allows changing
@@ -793,21 +769,19 @@
    *         the caller is not granted the permission to control
    *         the logging infrastructure.
    */
-  public void checkAccess()
-    throws SecurityException
+  public void checkAccess() throws SecurityException
   {
     SecurityManager sm = System.getSecurityManager();
     if (sm != null)
       sm.checkPermission(controlPermission);
   }
 
-
-  /** 
+  /**
    * Creates a new instance of a class specified by name.
    *
    * @param className the name of the class of which a new instance
    *        should be created.
-   *       
+   *
    * @param ofClass the class to which the new instance should
    *        be either an instance or an instance of a subclass.
    *        FIXME: This description is just terrible.
@@ -820,26 +794,26 @@
    */
   static final Object createInstance(String className, Class ofClass)
   {
-    Class   klass;
+    Class klass;
 
     if ((className == null) || (className.length() == 0))
       return null;
 
     try
-    {
-      klass = Class.forName(className);
-      if (!ofClass.isAssignableFrom(klass))
-	return null;
+      {
+	klass = Class.forName(className);
+	if (! ofClass.isAssignableFrom(klass))
+	  return null;
 
-      return klass.newInstance();
-    }
+	return klass.newInstance();
+      }
     catch (Exception _)
-    {
-      return null;
-    }
+      {
+	return null;
+      }
     catch (java.lang.LinkageError _)
-    {
-      return null;
-    }
+      {
+	return null;
+      }
   }
 }



More information about the kaffe mailing list