public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Follow class inheritance when creating loggers.
@ 2008-02-08 20:51 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-02-08 20:51 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  828ec80c296d95e06dfcabbcb77f7065f95611b8 (commit)
       via  7b49d5ce92430531a95ba44ef2cea1632d99cd8c (commit)
      from  d38d5031293d95fdc2cff53b8c6dd1beccd63819 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 828ec80c296d95e06dfcabbcb77f7065f95611b8
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Feb 8 15:49:55 2008 -0500

    Follow class inheritance when creating loggers.
    
    frysk-sys/frysk/rsl/ChangeLog
    2008-02-08  Andrew Cagney  <cagney@redhat.com>
    
    	* Node.java (get(String,Level)): Delete.
    	(get(Class)): New.
    	(extensions): New.
    	* LogFactory.java (get(Class,Level)): Delete.
    	(get(String,Level)): Delete.
    	* TestLog.java: Update.
    	* Logger.java: Update.

commit 7b49d5ce92430531a95ba44ef2cea1632d99cd8c
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Feb 8 12:30:30 2008 -0500

    Break up Log.
    
    frysk-sys/frysk/expunit/ChangeLog
    2008-02-08  Andrew Cagney  <cagney@redhat.com>
    
    	* Child.java: Update to match frysk.rsl.Log.
    	* Expect.java: Ditto.
    
    frysk-sys/frysk/rsl/ChangeLog
    2008-02-08  Andrew Cagney  <cagney@redhat.com>
    
    	* Log.java: Split into.
    	* LogFactory.java: Split from Log.java.
    	* Node.java: Rename Tree.java.
    	* Logger.java: Update.
    	* LogOption.java: Update.
    	* TestLog.java: Update.

-----------------------------------------------------------------------

Summary of changes:
 frysk-sys/frysk/expunit/ChangeLog                  |    5 ++
 frysk-sys/frysk/expunit/Child.java                 |    5 +-
 frysk-sys/frysk/expunit/Expect.java                |    3 +-
 frysk-sys/frysk/rsl/ChangeLog                      |   17 +++++
 frysk-sys/frysk/rsl/Log.java                       |   35 ++-------
 .../frysk/rsl/{Logger.java => LogFactory.java}     |   40 ++++++----
 frysk-sys/frysk/rsl/LogOption.java                 |    6 +-
 frysk-sys/frysk/rsl/Logger.java                    |    2 +-
 frysk-sys/frysk/rsl/{Tree.java => Node.java}       |   77 +++++++++++++-------
 frysk-sys/frysk/rsl/TestLog.java                   |   14 +++-
 10 files changed, 120 insertions(+), 84 deletions(-)
 copy frysk-sys/frysk/rsl/{Logger.java => LogFactory.java} (74%)
 rename frysk-sys/frysk/rsl/{Tree.java => Node.java} (74%)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/expunit/ChangeLog b/frysk-sys/frysk/expunit/ChangeLog
index 84ddcbc..ad00881 100644
--- a/frysk-sys/frysk/expunit/ChangeLog
+++ b/frysk-sys/frysk/expunit/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-08  Andrew Cagney  <cagney@redhat.com>
+
+	* Child.java: Update to match frysk.rsl.Log.
+	* Expect.java: Ditto.
+
 2008-02-06  Andrew Cagney  <cagney@redhat.com>
 
 	* WaitObserver.java: Update to match WaitBuilder's disappeared,
diff --git a/frysk-sys/frysk/expunit/Child.java b/frysk-sys/frysk/expunit/Child.java
index aacdacf..9aa43f6 100644
--- a/frysk-sys/frysk/expunit/Child.java
+++ b/frysk-sys/frysk/expunit/Child.java
@@ -44,15 +44,14 @@ import frysk.sys.ProcessIdentifier;
 import frysk.sys.PseudoTerminal;
 import frysk.sys.Signal;
 import frysk.rsl.Log;
-import frysk.rsl.Level;
 
 /**
  * The child being waited on.
  */
 
 class Child {
-    static protected Log fine = Log.get(Child.class, Level.FINE);
-    static private Log finest = Log.get(Child.class, Level.FINEST);
+    static protected Log fine = Log.fine(Child.class);
+    static private Log finest = Log.finest(Child.class);
 
     private final PseudoTerminal child;
     private final ProcessIdentifier pid;
diff --git a/frysk-sys/frysk/expunit/Expect.java b/frysk-sys/frysk/expunit/Expect.java
index fd3072a..1d07b91 100644
--- a/frysk-sys/frysk/expunit/Expect.java
+++ b/frysk-sys/frysk/expunit/Expect.java
@@ -42,7 +42,6 @@ package frysk.expunit;
 import frysk.sys.ProcessIdentifier;
 import frysk.sys.Signal;
 import frysk.rsl.Log;
-import frysk.rsl.Level;
 import java.io.File;
 
 /**
@@ -55,7 +54,7 @@ import java.io.File;
  */
 
 public class Expect {
-    private static final Log fine = Log.get(Expect.class, Level.FINE);
+    private static final Log fine = Log.fine(Expect.class);
 
     private final Child child;
     private final long timeoutMilliseconds;
diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog
index 1284dad..d1ba3af 100644
--- a/frysk-sys/frysk/rsl/ChangeLog
+++ b/frysk-sys/frysk/rsl/ChangeLog
@@ -1,3 +1,20 @@
+2008-02-08  Andrew Cagney  <cagney@redhat.com>
+
+	* Node.java (get(String,Level)): Delete.
+	(get(Class)): New.
+	(extensions): New.
+	* LogFactory.java (get(Class,Level)): Delete.
+	(get(String,Level)): Delete.
+	* TestLog.java: Update.
+	* Logger.java: Update.
+	
+	* Log.java: Split into.
+	* LogFactory.java: Split from Log.java.
+	* Node.java: Rename Tree.java.
+	* Logger.java: Update.
+	* LogOption.java: Update.
+	* TestLog.java: Update.
+
 2008-01-15  Andrew Cagney  <cagney@redhat.com>
 
 	* Log.java (print(char)): New.
diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Log.java
index ebb7bd9..d78fd7d 100644
--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Log.java
@@ -40,7 +40,6 @@
 package frysk.rsl;
 
 import java.io.PrintStream;
-import java.util.List;
 import java.text.MessageFormat;
 import java.lang.reflect.Array;
 
@@ -101,35 +100,17 @@ public final class Log {
 	return logging;
     }
 
-    public static Tree get(String klass) {
-	return Tree.root.get(klass);
-    }
-    public static Log get(String klass, Level level) {
-	return Tree.root.get(klass, level);
-    }
-    public static Log fine(String klass) {
-	return get(klass, Level.FINE);
-    }
-    
-    public static Log finest(String klass) {
-	return get(klass, Level.FINEST);
-    }
-
-    public static Tree get(Class klass) {
-	return get(klass.getName());
-    }
-    public static Log get(Class klass, Level level) {
-	return get(klass.getName(), level);
-    }
+    /**
+     * For convenience, grab the FINE logger.
+     */
     public static Log fine(Class klass) {
-	return fine(klass.getName());
+	return LogFactory.fine(klass);
     }
+    /**
+     * For convenience, grab the FINEST logger.
+     */
     public static Log finest(Class klass) {
-	return finest(klass.getName());
-    }
-
-    public static int complete(String incomplete, List candidates) {
-	return Tree.root.complete(incomplete, candidates);
+	return LogFactory.finest(klass);
     }
 
     // Static?
diff --git a/frysk-sys/frysk/rsl/Logger.java b/frysk-sys/frysk/rsl/LogFactory.java
similarity index 74%
copy from frysk-sys/frysk/rsl/Logger.java
copy to frysk-sys/frysk/rsl/LogFactory.java
index 856f6ac..899fa86 100644
--- a/frysk-sys/frysk/rsl/Logger.java
+++ b/frysk-sys/frysk/rsl/LogFactory.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 // 
-// Copyright 2007, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 // 
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -39,26 +39,34 @@
 
 package frysk.rsl;
 
+import java.util.List;
+
 /**
- * Java logger compatibility class; to aid easy conversion.
+ * Create the specified logger.
  */
-public final class Logger {
-    public static Logger getLogger(String path) {
-	return new Logger(path);
+public final class LogFactory {
+
+    public static Node get(String klass) {
+	return Node.root.get(klass);
+    }
+    public static Log fine(String klass) {
+	return get(klass).get(Level.FINE);
     }
-    private final Log[] logger = new Log[Level.MAX.intValue()];
-    private Logger(String path) {
-	for (int i = 0; i < Level.MAX.intValue(); i++) {
-	    this.logger[i] = Log.get(path, Level.valueOf(i));
-	}
+    public static Log finest(String klass) {
+	return get(klass).get(Level.FINEST);
     }
-    public boolean isLoggable(Level level) {
-	return logger[level.intValue()].logging();
+
+    public static Node get(Class klass) {
+	return Node.root.get(klass);
+    }
+    public static Log fine(Class klass) {
+	return get(klass).get(Level.FINE);
     }
-    public void log(Level level, String message, Object[] param) {
-	logger[level.intValue()].format(message, param);
+    public static Log finest(Class klass) {
+	return get(klass).get(Level.FINEST);
     }
-    public void log(Level level, String message, Object param) {
-	logger[level.intValue()].format(message, param);
+
+    public static int complete(String incomplete, List candidates) {
+	return Node.root.complete(incomplete, candidates);
     }
 }
diff --git a/frysk-sys/frysk/rsl/LogOption.java b/frysk-sys/frysk/rsl/LogOption.java
index 1689e01..91555a2 100644
--- a/frysk-sys/frysk/rsl/LogOption.java
+++ b/frysk-sys/frysk/rsl/LogOption.java
@@ -61,16 +61,16 @@ public class LogOption extends Option {
      * Parse ARG0 setting log levels.
      */
     public static void level(String arg0) throws OptionException {
-	level(Tree.root, arg0);
+	level(Node.root, arg0);
     }
     /**
      * Parse ARG0 setting log levels.
      */
-    static void level(Tree root, String arg0) throws OptionException {
+    static void level(Node root, String arg0) throws OptionException {
 	String[] logs = arg0.split(",");
 	for (int i = 0; i < logs.length; i++) {
 	    String[] logLevel = logs[i].split("=");
-	    Tree logger;
+	    Node logger;
 	    Level level;
 	    switch (logLevel.length) {
 	    case 1:
diff --git a/frysk-sys/frysk/rsl/Logger.java b/frysk-sys/frysk/rsl/Logger.java
index 856f6ac..e498cb8 100644
--- a/frysk-sys/frysk/rsl/Logger.java
+++ b/frysk-sys/frysk/rsl/Logger.java
@@ -49,7 +49,7 @@ public final class Logger {
     private final Log[] logger = new Log[Level.MAX.intValue()];
     private Logger(String path) {
 	for (int i = 0; i < Level.MAX.intValue(); i++) {
-	    this.logger[i] = Log.get(path, Level.valueOf(i));
+	    this.logger[i] = LogFactory.get(path).get(Level.valueOf(i));
 	}
     }
     public boolean isLoggable(Level level) {
diff --git a/frysk-sys/frysk/rsl/Tree.java b/frysk-sys/frysk/rsl/Node.java
similarity index 74%
rename from frysk-sys/frysk/rsl/Tree.java
rename to frysk-sys/frysk/rsl/Node.java
index 517b88c..bc9a281 100644
--- a/frysk-sys/frysk/rsl/Tree.java
+++ b/frysk-sys/frysk/rsl/Node.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 // 
-// Copyright 2007, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 // 
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -46,15 +46,18 @@ import java.util.List;
 /**
  * Generate log information when enabled.
  */
-public final class Tree {
+public final class Node {
 
+    // The children of this node, indexed by name.
     private final TreeMap children = new TreeMap();
+    // The extensions of this node, indexed by name.
+    private final TreeMap extensions = new TreeMap();
     private final Log[] loggers = new Log[Level.MAX.intValue()];
     private Level level;
-    private final String path;
-    private final String name;
+    private final String path; // path.to.Node
+    private final String name; // Node
 
-    private Tree(String path, String name, Level level) {
+    private Node(String path, String name, Level level) {
 	this.path = path;
 	this.name = name;
 	this.level = level;
@@ -70,16 +73,16 @@ public final class Tree {
     /**
      * Package private for testing.
      */
-    Tree() {
+    Node() {
 	this("<root>", "<root>", Level.NONE);
     }
     /**
-     * The root note; also serves as a single global lock.
+     * The root Node; also serves as a single global lock.
      */
-    static final Tree root = new Tree();
+    static final Node root = new Node();
 
     /**
-     * Set this logger's logging level.
+     * Set this Node, and all sub-notes logging level.
      */
     public final void set(Level level) {
 	synchronized (root) {
@@ -90,16 +93,20 @@ public final class Tree {
 		}
 	    }
 	    for (Iterator i = children.values().iterator(); i.hasNext(); ) {
-		Tree child = (Tree)i.next();
+		Node child = (Node)i.next();
 		child.set(level);
 	    }
+	    for (Iterator i = extensions.values().iterator(); i.hasNext(); ) {
+		Node extension = (Node)i.next();
+		extension.set(level);
+	    }
 	}
     }
 
     /**
      * POS starts at -1, then points at "." or the end of the name.
      */
-    private Tree get(String path, int pos) {
+    private Node get(String path, int pos) {
 	if (pos >= path.length()) {
 	    // Reached end if the string; find the logger.
 	    return this;
@@ -112,40 +119,54 @@ public final class Tree {
 	    if (dot < 0)
 		dot = path.length();
 	    String name = path.substring(pos + 1, dot);
-	    Tree child = (Tree)children.get(name);
+	    Node child = (Node)children.get(name);
 	    if (child == null) {
-		child = new Tree(path.substring(0, dot), name, level);
+		child = new Node(path.substring(0, dot), name, level);
 		children.put(name, child);
 	    }
 	    return child.get(path, dot);
 	}
     }
-    Tree get(String path) {
+    Node get(String path) {
 	synchronized (root) {
 	    return get(path, -1);
 	}
     }
 
-    /**
-     * Return the requested level.
-     */
-    private Log get(Level level) {
-	int l = level.intValue();
-	if (loggers[l] == null) {
-	    loggers[l] = new Log(path, name, level).set(this.level);
+    Node get(Class klass) {
+	synchronized (root) {
+	    Node childNode = get(klass.getName());
+	    Class parentClass = klass.getSuperclass();
+	    if (parentClass != null) {
+		Node parentNode = get(parentClass);
+		// Did the parent class know about this child class?
+		if (!parentNode.extensions.containsKey(childNode.path)) {
+		    // It didn't need to link it in; and ...
+		    parentNode.extensions.put(childNode.path, childNode);
+		    // .. make certain that the child's logging level
+		    // is at least equal to the parent's logging
+		    // level.  XXX: This compareTo() is backwards!
+		    if (childNode.level.compareTo(parentNode.level) > 0)
+			childNode.set(parentNode.level);
+		}
+	    }
+	    return childNode;
 	}
-	return loggers[l];
     }
+
     /**
-     * Return the requested logger.
+     * Return the requested level.
      */
-    Log get(String path, Level level) {
+    Log get(Level level) {
 	synchronized (root) {
-	    return get(path, -1).get(level);
+	    int l = level.intValue();
+	    if (loggers[l] == null) {
+		loggers[l] = new Log(path, name, level).set(this.level);
+	    }
+	    return loggers[l];
 	}
     }
 
-
     /**
      * Complete the logger.  On entry, POS is either -1 or the
      * location of the last DOT indicating further name completion is
@@ -161,7 +182,7 @@ public final class Tree {
 	if (dot >= 0) {
 	    // More tokens to follow; recursively resolve.
 	    String name = incomplete.substring(pos + 1, dot);
-	    Tree child = (Tree)children.get(name);
+	    Node child = (Node)children.get(name);
 	    if (child == null)
 		return -1;
 	    else
@@ -178,7 +199,7 @@ public final class Tree {
 	    case 0:
 		return -1;
 	    case 1:
-		Tree child = (Tree)children.get(name);
+		Node child = (Node)children.get(name);
 		if (child != null) {
 		    // The final NAME was an exact match for a child;
 		    // and there are no other possible completions
diff --git a/frysk-sys/frysk/rsl/TestLog.java b/frysk-sys/frysk/rsl/TestLog.java
index 971a255..19a9af8 100644
--- a/frysk-sys/frysk/rsl/TestLog.java
+++ b/frysk-sys/frysk/rsl/TestLog.java
@@ -49,20 +49,20 @@ import java.util.LinkedList;
 public class TestLog extends TestCase {
     private static final Log log = Log.fine(TestLog.class);
 
-    private Tree root;
+    private Node root;
     public void setUp() {
 	log.log("setUp");
-	root = new Tree();
+	root = new Node();
     }
     public void tearDown() {
 	log.log("tearDown");
 	root = null;
     }
-    private Tree get(String path) {
+    private Node get(String path) {
 	return root.get(path);
     }
     private Log get(String path, Level level) {
-	return root.get(path, level);
+	return root.get(path).get(level);
     }
 
     public void testRoot() {
@@ -141,6 +141,12 @@ public class TestLog extends TestCase {
 	checkLevel("", Level.NONE);
     }
     
+    public void testSubClassFINE() {
+	root.get(TestCase.class).set(Level.FINE);
+	assertTrue("this is loggging",
+		   root.get(TestLog.class).get(Level.FINE).logging());
+    }
+
     private void checkComplete(String incomplete, int expectedCursor,
 			       String[] expectedCandidates) {
 	// create a tree.


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-08 20:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-08 20:51 [SCM] master: Follow class inheritance when creating loggers cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).