public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM] master: Move tree code from Log.java to Tree.java.
Date: Fri, 07 Dec 2007 22:51:00 -0000 [thread overview]
Message-ID: <20071207225140.19042.qmail@sourceware.org> (raw)
The branch, master has been updated
via 86395789e16a674353533d7b897df0f24ce4d2df (commit)
from 36cff033d7840d1968d9952a44486abbe3b26b3f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 86395789e16a674353533d7b897df0f24ce4d2df
Author: Andrew Cagney <cagney@redhat.com>
Date: Fri Dec 7 17:49:06 2007 -0500
Move tree code from Log.java to Tree.java.
frysk-sys/frysk/rsl/ChangeLog
2007-12-07 Andrew Cagney <cagney@redhat.com>
* LogOption.java: New file.
* Branch.java: New.
* Level.mkenum: Add MAX.
* Log.java (print(int)): New.
(print(long)): New.
(print(String)): New.
(print(Object)): New.
(print(int[])): New.
(print(long[])): New.
(print(String[])): New.
(print(Object[])): New.
(fine(...), finest(...)): New.
(Log()): Moved to Branch.
(children): Moved to Branch.
(fine(...), finest(...)): Delete.
(get(String,int)): Move to Branch.
(complete(String,int,List)): Move to Branch.
* package.html: Update.
* TestLog.java: Update.
-----------------------------------------------------------------------
Summary of changes:
frysk-sys/frysk/rsl/{Log.java => Branch.java} | 180 +++--------
frysk-sys/frysk/rsl/ChangeLog | 20 ++
frysk-sys/frysk/rsl/Level.mkenum | 1 +
frysk-sys/frysk/rsl/Log.java | 337 ++++++++++++--------
.../frysk/rsl/LogOption.java | 49 ++--
frysk-sys/frysk/rsl/TestLog.java | 35 ++-
6 files changed, 314 insertions(+), 308 deletions(-)
copy frysk-sys/frysk/rsl/{Log.java => Branch.java} (57%)
copy frysk-core/frysk/event/TestSigChild.java => frysk-sys/frysk/rsl/LogOption.java (70%)
First 500 lines of diff:
diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Branch.java
similarity index 57%
copy from frysk-sys/frysk/rsl/Log.java
copy to frysk-sys/frysk/rsl/Branch.java
index 964f919..b1856d9 100644
--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Branch.java
@@ -39,7 +39,6 @@
package frysk.rsl;
-import java.io.PrintStream;
import java.util.TreeMap;
import java.util.Iterator;
import java.util.List;
@@ -47,99 +46,81 @@ import java.util.List;
/**
* Generate log information when enabled.
*/
-public final class Log {
+public final class Branch {
- private int level;
+ private final TreeMap children = new TreeMap();
+ private final Log[] loggers = new Log[Level.MAX.intValue()];
+ private Level level = Level.NONE;
private final String path;
private final String name;
- private Log(String path, String name, Log parent) {
+
+ private Branch(String path, String name) {
this.path = path;
- this.level = parent.level;
this.name = name;
}
/**
- * Create a root logger; package private so that test code can
- * create their own root logger.
+ * Package private for testing.
*/
- Log() {
- this.level = 0;
- this.path = "";
- this.name = "";
- }
-
- public String toString() {
- return ("{" + super.toString()
- + ",path=" + path
- + ",level=" + level
- + "}");
+ Branch() {
+ this("<root>", "<root>");
}
-
/**
- * Return the "basename" of the logger.
+ * The root note; also serves as a single global lock.
*/
- public final String name() {
- return name;
- }
- /**
- * Return the full path of the logger.
- */
- public final String path() {
- return path;
- }
+ static final Branch root = new Branch();
- private final TreeMap children = new TreeMap();
/**
* Set this logger's logging level.
*/
- public synchronized final Log set(Level level) {
- this.level = level.intValue();
- for (Iterator i = children.values().iterator(); i.hasNext(); ) {
- Log child = (Log)i.next();
- child.set(level);
+ public final void set(Level level) {
+ synchronized (root) {
+ this.level = level;
+ for (int i = 0; i < Level.MAX.intValue(); i++) {
+ if (loggers[i] != null) {
+ loggers[i].set(i >= level.intValue());
+ }
+ }
+ for (Iterator i = children.values().iterator(); i.hasNext(); ) {
+ Branch child = (Branch)i.next();
+ child.set(level);
+ }
}
- return this;
- }
- /**
- * Return this loggers current logging level.
- */
- public final Level level() {
- return Level.valueOf(level);
}
/**
* POS starts at -1, then points at "." or the end of the name.
* Package private so it can be called from test code.
*/
- synchronized final Log get(String path, int pos) {
- if (pos >= path.length())
- // Reached end if the string.
+ final Branch get(String path, int pos) {
+ if (pos >= path.length()) {
+ // Reached end if the string; find the logger.
return this;
- // Split
- int dot = path.indexOf(".", pos + 1);
- if (dot < 0)
- dot = path.length();
- String name = path.substring(pos + 1, dot);
- Log child = (Log)children.get(name);
- if (child == null) {
- child = new Log(path.substring(0, dot), name, this);
- children.put(name, child);
+ } else {
+ // Split
+ int dot = path.indexOf(".", pos + 1);
+ if (dot < 0)
+ dot = path.length();
+ String name = path.substring(pos + 1, dot);
+ Branch child = (Branch)children.get(name);
+ if (child == null) {
+ child = new Branch(path.substring(0, dot), name);
+ children.put(name, child);
+ }
+ return child.get(path, dot);
}
- return child.get(path, dot);
}
- private static final Log root = new Log();
- /**
- * Find the logger by the name KLASS.
- */
- public static Log get(String klass) {
- return root.get(klass, -1);
- }
/**
- * Find the logger by with KLASS's name.
+ * Return the requested level.
*/
- public static Log get(Class klass) {
- return root.get(klass.getName(), -1);
+ final Log get(Level level) {
+ int l = level.intValue();
+ if (loggers[l] == null) {
+ loggers[l] = new Log(path, name, level,
+ this.level.compareTo(level) >= 0);
+ }
+ return loggers[l];
}
/**
@@ -153,13 +134,13 @@ public final class Log {
*
* Package private to allow testing.
*/
- synchronized final int complete(String incomplete, int pos,
- List candidates) {
+ final int complete(String incomplete, int pos,
+ List candidates) {
int dot = incomplete.indexOf('.', pos + 1);
if (dot >= 0) {
// More tokens to follow; recursively resolve.
String name = incomplete.substring(pos + 1, dot);
- Log child = (Log)children.get(name);
+ Branch child = (Branch)children.get(name);
if (child == null)
return -1;
else
@@ -176,7 +157,7 @@ public final class Log {
case 0:
return -1;
case 1:
- Log child = (Log)children.get(name);
+ Branch child = (Branch)children.get(name);
if (child != null) {
// The final NAME was an exact match for a child;
// and there are no other possible completions
@@ -201,65 +182,4 @@ public final class Log {
}
}
}
-
- /**
- * Complete the logger path using constructed loggers. Return the
- * offset into incomplete where the completions apply, or -1 when
- * no completions.
- */
- public static int complete(String incomplete, List candidates) {
- return root.complete(incomplete, -1, candidates);
- }
-
- // Static?
- private static PrintStream out = System.out;
- static void set(PrintStream out) {
- Log.out = out;
- }
-
- private void prefix() {
- out.print(path);
- out.print(": ");
- }
-
- private void prefix(Object o) {
- out.print(path);
- out.print("[");
- out.print(o.toString());
- out.print("]: ");
- }
-
- private void postfix() {
- out.println();
- }
-
- // Add at will and on demand.
- private void log(String s1) {
- prefix();
- out.print(s1);
- postfix();
- }
- public final void fine(String s1) {
- log(s1);
- }
- public final void finest(String s1) {
- log(s1);
- }
-
- // Add at will and on demand.
- private void log(Object self, String s1) {
- prefix(self);
- out.print(s1);
- postfix();
- }
- public final void fine(Object self, String s1) {
- if (level < Level.FINE_)
- return;
- log(self, s1);
- }
- public final void finest(Object self, String s1) {
- if (level < Level.FINEST_)
- return;
- log(self, s1);
- }
}
diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog
index a7f1335..2141ae3 100644
--- a/frysk-sys/frysk/rsl/ChangeLog
+++ b/frysk-sys/frysk/rsl/ChangeLog
@@ -1,5 +1,25 @@
2007-12-07 Andrew Cagney <cagney@redhat.com>
+ * LogOption.java: New file.
+ * Branch.java: New.
+ * Level.mkenum: Add MAX.
+ * Log.java (print(int)): New.
+ (print(long)): New.
+ (print(String)): New.
+ (print(Object)): New.
+ (print(int[])): New.
+ (print(long[])): New.
+ (print(String[])): New.
+ (print(Object[])): New.
+ (fine(...), finest(...)): New.
+ (Log()): Moved to Branch.
+ (children): Moved to Branch.
+ (fine(...), finest(...)): Delete.
+ (get(String,int)): Move to Branch.
+ (complete(String,int,List)): Move to Branch.
+ * package.html: Update.
+ * TestLog.java: Update.
+
* TestLog.java (testCompletion()): New.
(checkComplete(String,int,String[])): New.
(testName()): New.
diff --git a/frysk-sys/frysk/rsl/Level.mkenum b/frysk-sys/frysk/rsl/Level.mkenum
index 5deb651..513ac9d 100644
--- a/frysk-sys/frysk/rsl/Level.mkenum
+++ b/frysk-sys/frysk/rsl/Level.mkenum
@@ -1,3 +1,4 @@
NONE 0
FINE 1
FINEST 2
+MAX 3
diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Log.java
index 964f919..dfaaeb7 100644
--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Log.java
@@ -40,8 +40,6 @@
package frysk.rsl;
import java.io.PrintStream;
-import java.util.TreeMap;
-import java.util.Iterator;
import java.util.List;
/**
@@ -49,23 +47,15 @@ import java.util.List;
*/
public final class Log {
- private int level;
private final String path;
private final String name;
- private Log(String path, String name, Log parent) {
+ private final Level level;
+ private boolean logging;
+ Log(String path, String name, Level level, boolean logging) {
this.path = path;
- this.level = parent.level;
this.name = name;
- }
-
- /**
- * Create a root logger; package private so that test code can
- * create their own root logger.
- */
- Log() {
- this.level = 0;
- this.path = "";
- this.name = "";
+ this.level = level;
+ this.logging = logging;
}
public String toString() {
@@ -78,137 +68,61 @@ public final class Log {
/**
* Return the "basename" of the logger.
*/
- public final String name() {
+ public String name() {
return name;
}
/**
* Return the full path of the logger.
*/
- public final String path() {
+ public String path() {
return path;
}
-
- private final TreeMap children = new TreeMap();
/**
- * Set this logger's logging level.
+ * The level at which this logger starts logging.
*/
- public synchronized final Log set(Level level) {
- this.level = level.intValue();
- for (Iterator i = children.values().iterator(); i.hasNext(); ) {
- Log child = (Log)i.next();
- child.set(level);
- }
- return this;
+ public Level level() {
+ return level;
}
/**
- * Return this loggers current logging level.
+ * Enable logging; package private.
*/
- public final Level level() {
- return Level.valueOf(level);
+ void set(boolean logging) {
+ this.logging = logging;
}
/**
- * POS starts at -1, then points at "." or the end of the name.
- * Package private so it can be called from test code.
+ * Return if this logger is currently enabled for logging.
*/
- synchronized final Log get(String path, int pos) {
- if (pos >= path.length())
- // Reached end if the string.
- return this;
- // Split
- int dot = path.indexOf(".", pos + 1);
- if (dot < 0)
- dot = path.length();
- String name = path.substring(pos + 1, dot);
- Log child = (Log)children.get(name);
- if (child == null) {
- child = new Log(path.substring(0, dot), name, this);
- children.put(name, child);
- }
- return child.get(path, dot);
+ public boolean logging() {
+ return logging;
}
- private static final Log root = new Log();
- /**
- * Find the logger by the name KLASS.
- */
- public static Log get(String klass) {
- return root.get(klass, -1);
+ public static Branch get(String klass) {
+ synchronized (Branch.root) {
+ return Branch.root.get(klass, -1);
+ }
}
- /**
- * Find the logger by with KLASS's name.
- */
- public static Log get(Class klass) {
- return root.get(klass.getName(), -1);
+ public static Log fine(String klass) {
+ return get(klass).get(Level.FINE);
+ }
+ public static Log finest(String klass) {
+ return get(klass).get(Level.FINEST);
}
- /**
- * Complete the logger. On entry, POS is either -1 or the
- * location of the last DOT indicating further name completion is
- * needed; or the length indicating that either a "." or " "
- * completion is needed.
- *
- * Returns the offset into INCOMPLETE that the completions apply
- * to, or -1.
- *
- * Package private to allow testing.
- */
- synchronized final int complete(String incomplete, int pos,
- List candidates) {
- int dot = incomplete.indexOf('.', pos + 1);
- if (dot >= 0) {
- // More tokens to follow; recursively resolve.
- String name = incomplete.substring(pos + 1, dot);
- Log child = (Log)children.get(name);
- if (child == null)
- return -1;
- else
- return child.complete(incomplete, dot, candidates);
- } else {
- // Final token, scan children for all partial matches.
- String name = incomplete.substring(pos + 1);
- for (Iterator i = children.keySet().iterator(); i.hasNext(); ) {
- String child = (String)i.next();
- if (child.startsWith(name))
- candidates.add(child);
- }
- switch (candidates.size()) {
- case 0:
- return -1;
- case 1:
- Log child = (Log)children.get(name);
- if (child != null) {
- // The final NAME was an exact match for a child;
- // and there are no other possible completions
- // (size == 1); change the expansion to either "."
- // (have children) or " " (childless).
- candidates.remove(0);
- synchronized (child) {
- if (child.children.size() > 0) {
- candidates.add(".");
- } else {
- candidates.add(" ");
- }
- return incomplete.length();
- }
- } else {
- // A single partial completion e.g., <<foo<TAB>>>
- // -> <<foobar>>.
- return pos + 1;
- }
- default:
- return pos + 1;
- }
- }
+ public static Branch get(Class klass) {
+ return get(klass.getName());
+ }
+ public static Log fine(Class klass) {
+ return fine(klass.getName());
+ }
+ public static Log finest(Class klass) {
+ return finest(klass.getName());
}
- /**
- * Complete the logger path using constructed loggers. Return the
- * offset into incomplete where the completions apply, or -1 when
- * no completions.
- */
public static int complete(String incomplete, List candidates) {
- return root.complete(incomplete, -1, candidates);
+ synchronized (Branch.root) {
+ return Branch.root.complete(incomplete, -1, candidates);
+ }
hooks/post-receive
--
frysk system monitor/debugger
reply other threads:[~2007-12-07 22:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071207225140.19042.qmail@sourceware.org \
--to=cagney@sourceware.org \
--cc=frysk-cvs@sourceware.org \
--cc=frysk@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).