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 print code to separate class.
Date: Fri, 04 Apr 2008 17:17:00 -0000 [thread overview]
Message-ID: <20080404171700.25508.qmail@sourceware.org> (raw)
The branch, master has been updated
via 2b69f5e052f189aa23342a448987139fa3a44231 (commit)
from 246616427a876f8fff03660b0b59ee034e76d517 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 2b69f5e052f189aa23342a448987139fa3a44231
Author: Andrew Cagney <cagney@redhat.com>
Date: Fri Apr 4 13:15:54 2008 -0400
Move print code to separate class.
frysk-sys/frysk/rsl/ChangeLog
2008-04-04 Andrew Cagney <cagney@redhat.com>
* Log.java: Move printing code to ...
* Printer.java: here. New.
* TestCallers.java: Update.
-----------------------------------------------------------------------
Summary of changes:
frysk-sys/frysk/rsl/ChangeLog | 6 +
frysk-sys/frysk/rsl/Log.java | 244 ++---------------------------
frysk-sys/frysk/rsl/Printer.java | 286 ++++++++++++++++++++++++++++++++++
frysk-sys/frysk/rsl/TestCallers.java | 10 +-
4 files changed, 308 insertions(+), 238 deletions(-)
create mode 100644 frysk-sys/frysk/rsl/Printer.java
First 500 lines of diff:
diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog
index 5a20a52..353843f 100644
--- a/frysk-sys/frysk/rsl/ChangeLog
+++ b/frysk-sys/frysk/rsl/ChangeLog
@@ -1,3 +1,9 @@
+2008-04-04 Andrew Cagney <cagney@redhat.com>
+
+ * Log.java: Move printing code to ...
+ * Printer.java: here. New.
+ * TestCallers.java: Update.
+
2008-04-02 Petr Machata <pmachata@redhat.com>
* Log.java (log(String,long,String,long,String,Object)): New.
diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Log.java
index fd228c4..7a71cfe 100644
--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Log.java
@@ -39,11 +39,8 @@
package frysk.rsl;
-import frysk.sys.Tid;
-import frysk.sys.Pid;
import inua.util.PrintWriter;
import java.io.PrintStream;
-import java.lang.reflect.Array;
/**
* Generate log information when enabled.
@@ -111,244 +108,25 @@ public final class Log {
}
// Static?
- private static PrintWriter out = new PrintWriter(System.out);
- static PrintWriter set(PrintStream out) {
- PrintWriter old = Log.out;
- Log.out = new PrintWriter(out);
- return old;
- }
- static PrintWriter set(PrintWriter out) {
- PrintWriter old = Log.out;
+ private static Printer out = new Printer(new PrintWriter(System.out));
+ static Printer set(Printer out) {
+ Printer old = Log.out;
Log.out = out;
return old;
}
-
- private static final long startTime = System.currentTimeMillis();
-
- private void prefixTimeAndPid() {
- if (level.compareTo(Level.DEFAULT) <= 0) {
- // Prefix user visible log messages with the severity; but
- // leave it off debugging messages.
- out.print(level.toPrint());
- out.print(": ");
- }
- long time = System.currentTimeMillis() - startTime;
- long millis = time % 1000;
- time = time / 1000;
- long secs = time % 60;
- time = time / 60;
- long mins = time % 60;
- time = time / 60;
- long hrs = time % 24;
- time = time / 24;
- long days = time;
- if (days > 0) {
- out.print(days);
- out.print(' ');
- }
- out.print(2, '0', hrs);
- out.print(':');
- out.print(2, '0', mins);
- out.print(':');
- out.print(2, '0', secs);
- out.print('.');
- out.print(3, '0', millis);
- out.print(' ');
- out.print(Pid.get());
- out.print('.');
- out.print(Tid.get());
- out.print(' ');
- }
-
- public Log prefix() {
- prefixTimeAndPid();
- out.print(path);
- out.print(":");
- return this;
- }
-
- public Log prefix(Object o) {
- prefixTimeAndPid();
- out.print("[");
- out.print(o.toString());
- out.print("]:");
- return this;
- }
-
- public void suffix() {
- out.println();
- out.flush();
- }
-
- /**
- * Use poorly implemented reflection to dump Objects.
- */
- public Log print(Object o) {
- out.print(' ');
- dump(o);
- return this;
- }
- private void dump(Object o) {
- if (o == null) {
- out.print("<<null>>");
- } else if (o instanceof char[]) {
- dump((char[])o);
- } else if (o instanceof boolean[]) {
- dump((boolean[])o);
- } else if (o instanceof int[]) {
- dump((int[])o);
- } else if (o instanceof long[]) {
- dump((long[])o);
- } else if (o.getClass().isArray()) {
- out.print("[");
- for (int i = 0; i < Array.getLength(o); i++) {
- if (i > 0)
- out.print(",");
- dump(o, i);
- }
- out.print("]");
- } else if (o instanceof Throwable) {
- dump((Throwable) o);
- } else if (o instanceof String) {
- dump((String)o);
- } else {
- out.print("<<");
- out.print(o.toString());
- out.print(">>");
- }
- }
- /**
- * Throwables get their message printed; along with any root
- * causes.
- */
- private void dump(Throwable t) {
- out.print("<<exception ");
- out.print(t.toString());
- for (Throwable cause = t.getCause(); cause != null;
- cause = cause.getCause()) {
- out.print(" <caused-by> ");
- out.print(cause.toString());
- }
- out.print(">>");
- }
- private void dump(String s) {
- out.print("\"");
- out.print(s
- .replaceAll("\"", "\\\\\"")
- .replaceAll("\'", "\\\\\'")
- .replaceAll("\r", "\\\\r")
- .replaceAll("\n", "\\\\n")
- .replaceAll("\t", "\\\\t")
- .replaceAll("\f", "\\\\f"));
- out.print("\"");
- }
- /**
- * Dump the array object's i'th element
- * @param o the array object
- * @param i the array index
- */
- private void dump(Object o, int i) {
- // for moment assume the array contains Objects; dump recursively.
- dump(Array.get(o, i));
- }
-
- /**
- * Booleans are printed as strings.
- */
- public Log print(boolean b) {
- out.print(' ');
- dump(b);
- return this;
- }
- private void dump(boolean b) {
- out.print(b);
- }
- private void dump(boolean[] a) {
- out.print('[');
- for (int i = 0; i < a.length; i++) {
- if (i > 0)
- out.print(',');
- dump(a[i]);
- }
- out.print(']');
- }
-
- /**
- * Chars are printed in quotes.
- */
- public Log print(char c) {
- out.print(' ');
- dump(c);
- return this;
- }
- private void dump(char c) {
- out.print('\'');
- out.print(c);
- out.print('\'');
- }
- private void dump(char[] a) {
- out.print('[');
- for (int i = 0; i < a.length; i++) {
- if (i > 0)
- out.print(',');
- dump(a[i]);
- }
- out.print(']');
- }
-
- /**
- * Integers are printed in decimal.
- */
- public Log print(int i) {
- out.print(' ');
- dump(i);
- return this;
- }
- private void dump(int i) {
- out.print(i);
+ static Printer set(PrintStream out) {
+ return set(new Printer(new PrintWriter(out)));
}
- private void dump(int[] a) {
- out.print('[');
- for (int i = 0; i < a.length; i++) {
- if (i > 0)
- out.print(',');
- dump(a[i]);
- }
- out.print(']');
+ static Printer set(PrintWriter out) {
+ return set(new Printer(out));
}
-
- /**
- * Longs are printed in hex.
- */
- public Log print(long l) {
- out.print(' ');
- dump(l);
- return this;
+ public Printer prefix() {
+ return out.prefix(this);
}
- private void dump(long l) {
- out.print("0x");
- out.printx(l);
-
- }
- private void dump(long[] a) {
- out.print('[');
- for (int i = 0; i < a.length; i++) {
- if (i > 0)
- out.print(',');
- dump(a[i]);
- }
- out.print(']');
+ public Printer prefix(Object self) {
+ return out.prefix(this, self);
}
- /**
- * Strings are just copied.
- */
- public Log print(String s) {
- out.print(" ");
- out.print(s);
- return this;
- }
-
// static 1 parameter
public void log(String p1) {
if (!logging)
diff --git a/frysk-sys/frysk/rsl/Printer.java b/frysk-sys/frysk/rsl/Printer.java
new file mode 100644
index 0000000..a8e926d
--- /dev/null
+++ b/frysk-sys/frysk/rsl/Printer.java
@@ -0,0 +1,286 @@
+// This file is part of the program FRYSK.
+//
+// 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
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.rsl;
+
+import frysk.sys.Tid;
+import frysk.sys.Pid;
+import inua.util.PrintWriter;
+import java.lang.reflect.Array;
+
+/**
+ * Class for accumulating and then displaying log messages.
+ */
+public final class Printer {
+ private final PrintWriter out;
+
+ /**
+ * Start with this single printer, will eventually need to make
+ * things more complex with sub-classes.
+ */
+ Printer(PrintWriter out) {
+ this.out = out;
+ }
+
+ private static final long startTime = System.currentTimeMillis();
+
+ private void prefixTimeAndPid(Level level) {
+ if (level.compareTo(Level.DEFAULT) <= 0) {
+ // Prefix user visible log messages with the severity; but
+ // leave it off debugging messages.
+ print(level.toPrint());
+ out.print(": ");
+ }
+ long time = System.currentTimeMillis() - startTime;
+ long millis = time % 1000;
+ time = time / 1000;
+ long secs = time % 60;
+ time = time / 60;
+ long mins = time % 60;
+ time = time / 60;
+ long hrs = time % 24;
+ time = time / 24;
+ long days = time;
+ if (days > 0) {
+ out.print(days);
+ out.print(' ');
+ }
+ out.print(2, '0', hrs);
+ out.print(':');
+ out.print(2, '0', mins);
+ out.print(':');
+ out.print(2, '0', secs);
+ out.print('.');
+ out.print(3, '0', millis);
+ out.print(' ');
+ out.print(Pid.get());
+ out.print('.');
+ out.print(Tid.get());
+ out.print(' ');
+ }
+
+ public Printer prefix(Log logger) {
+ prefixTimeAndPid(logger.level());
+ out.print(logger.path());
+ out.print(":");
+ return this;
+ }
+
+ public Printer prefix(Log logger, Object o) {
+ prefixTimeAndPid(logger.level());
+ out.print("[");
+ out.print(o.toString());
+ out.print("]:");
+ return this;
+ }
+
+ public void suffix() {
+ out.println();
+ out.flush();
+ }
+
+ /**
+ * Use poorly implemented reflection to dump Objects.
+ */
+ public Printer print(Object o) {
+ out.print(' ');
+ dump(o);
+ return this;
+ }
+ private void dump(Object o) {
+ if (o == null) {
+ out.print("<<null>>");
+ } else if (o instanceof char[]) {
+ dump((char[])o);
+ } else if (o instanceof boolean[]) {
+ dump((boolean[])o);
+ } else if (o instanceof int[]) {
+ dump((int[])o);
+ } else if (o instanceof long[]) {
+ dump((long[])o);
+ } else if (o.getClass().isArray()) {
+ out.print("[");
+ for (int i = 0; i < Array.getLength(o); i++) {
+ if (i > 0)
+ out.print(",");
+ dump(o, i);
+ }
+ out.print("]");
+ } else if (o instanceof Throwable) {
+ dump((Throwable) o);
+ } else if (o instanceof String) {
+ dump((String)o);
+ } else {
+ out.print("<<");
+ out.print(o.toString());
+ out.print(">>");
+ }
+ }
+ /**
+ * Throwables get their message printed; along with any root
+ * causes.
+ */
+ private void dump(Throwable t) {
+ out.print("<<exception ");
+ out.print(t.toString());
+ for (Throwable cause = t.getCause(); cause != null;
+ cause = cause.getCause()) {
+ out.print(" <caused-by> ");
+ out.print(cause.toString());
+ }
+ out.print(">>");
+ }
+ private void dump(String s) {
+ out.print("\"");
+ out.print(s
+ .replaceAll("\"", "\\\\\"")
+ .replaceAll("\'", "\\\\\'")
+ .replaceAll("\r", "\\\\r")
+ .replaceAll("\n", "\\\\n")
+ .replaceAll("\t", "\\\\t")
+ .replaceAll("\f", "\\\\f"));
+ out.print("\"");
+ }
+ /**
+ * Dump the array object's i'th element
+ * @param o the array object
+ * @param i the array index
+ */
+ private void dump(Object o, int i) {
+ // for moment assume the array contains Objects; dump recursively.
+ dump(Array.get(o, i));
+ }
+
+ /**
+ * Booleans are printed as strings.
+ */
+ public Printer print(boolean b) {
+ out.print(' ');
+ dump(b);
+ return this;
+ }
+ private void dump(boolean b) {
+ out.print(b);
+ }
+ private void dump(boolean[] a) {
+ out.print('[');
+ for (int i = 0; i < a.length; i++) {
+ if (i > 0)
+ out.print(',');
+ dump(a[i]);
+ }
+ out.print(']');
hooks/post-receive
--
frysk system monitor/debugger
reply other threads:[~2008-04-04 17:17 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=20080404171700.25508.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).