public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Simplify log output formatting.
@ 2008-02-11 19:44 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-02-11 19:44 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  af5efc444c59457e9a2f9b77382ddd6073ee4edc (commit)
      from  9217bc52ea47dd010f68d87426a70b491cbf4689 (commit)

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

- Log -----------------------------------------------------------------
commit af5efc444c59457e9a2f9b77382ddd6073ee4edc
Author: Andrew Cagney <cagney@redhat.com>
Date:   Mon Feb 11 14:43:11 2008 -0500

    Simplify log output formatting.
    
    frysk-sys/frysk/rsl/ChangeLog
    2008-02-11  Andrew Cagney  <cagney@redhat.com>
    
    	* Log.java (prefixTime()): Print time in DAY HH:MM:SS.mmm format;
    	use inua.util.PrintWriter.
    	(log(String,String)): Simplify.
    	(log(Object,String,String)): Delete.
    	(log(String,char[])): Delete.
    	(log(Object,String,int[])): Delete.
    	(log(Object,String,long[])): Delete.
    	(dump(Object)): Check for instance of char[], int[] and long[].
    	(dump(char[])): Replace print(char[]).
    	(dump(int[])): Replace print(int[]).
    	(dump(long[])): Replace print(long[]).
    	(dump(char)): New.
    	(dump(int)): New.
    	(dump(long)): New.
    	* package.html: Update.

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

Summary of changes:
 frysk-sys/frysk/rsl/ChangeLog    |   16 +++++
 frysk-sys/frysk/rsl/Log.java     |  120 +++++++++++++++++++++-----------------
 frysk-sys/frysk/rsl/package.html |   10 ++--
 3 files changed, 87 insertions(+), 59 deletions(-)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog
index e87d3ac..a2997cf 100644
--- a/frysk-sys/frysk/rsl/ChangeLog
+++ b/frysk-sys/frysk/rsl/ChangeLog
@@ -1,5 +1,21 @@
 2008-02-11  Andrew Cagney  <cagney@redhat.com>
 
+	* Log.java (prefixTime()): Print time in DAY HH:MM:SS.mmm format;
+	use inua.util.PrintWriter.
+	(log(String,String)): Simplify.
+	(log(Object,String,String)): Delete.
+	(log(String,char[])): Delete.
+	(log(Object,String,int[])): Delete.
+	(log(Object,String,long[])): Delete.
+	(dump(Object)): Check for instance of char[], int[] and long[].
+	(dump(char[])): Replace print(char[]).
+	(dump(int[])): Replace print(int[]).
+	(dump(long[])): Replace print(long[]).
+	(dump(char)): New.
+	(dump(int)): New.
+	(dump(long)): New.
+	* package.html: Update.
+
 	* Log.java (log(String,Object,String,Object,String,Object,String,Object)): New.
 	(log(String,int)): New.
 	(log(String,long)): New.
diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Log.java
index 8e7cf96..1ddfa73 100644
--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Log.java
@@ -39,6 +39,7 @@
 
 package frysk.rsl;
 
+import inua.util.PrintWriter;
 import java.io.PrintStream;
 import java.text.MessageFormat;
 import java.lang.reflect.Array;
@@ -114,19 +115,34 @@ public final class Log {
     }
 
     // Static?
-    private static PrintStream out = System.out;
+    private static PrintWriter out = new PrintWriter(System.out);
     static void set(PrintStream out) {
-	Log.out = out;
+	Log.out = new PrintWriter(out);
     }
 
     private static final long startTime = System.currentTimeMillis();
 
     private void prefixTime() {
 	long time = System.currentTimeMillis() - startTime;
-	out.print(time / 1000);
-	out.print(".");
-	out.print(time % 1000);
-	out.print(": ");
+	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;
+	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(' ');
     }
 
     private void prefix() {
@@ -186,7 +202,13 @@ public final class Log {
      * @param o the object to dump
      */
     private void dump(Object o) {
-	if (o.getClass().isArray()) {
+	if (o instanceof char[]) {
+	    dump((char[])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)
@@ -208,7 +230,7 @@ public final class Log {
      * Use poorly implemented reflection to dump Objects.
      */
     private void print(Object o) {
-	out.print(" ");
+	out.print(' ');
 	dump(o);
     }
     
@@ -216,56 +238,66 @@ public final class Log {
      * Chars are printed in quotes.
      */
     private void print(char c) {
-	out.print(" '");
+	out.print(' ');
+	dump(c);
+    }
+    private void dump(char c) {
+	out.print('\'');
 	out.print(c);
-	out.print("'");
+	out.print('\'');
     }
-    private void print(char[] a) {
-	out.print(" {");
+    private void dump(char[] a) {
+	out.print('[');
 	for (int i = 0; i < a.length; i++) {
 	    if (i > 0)
 		out.print(',');
-	    out.print('\'');
-	    out.print(a[i]);
-	    out.print('\'');
+	    dump(a[i]);
 	}
-	out.print('}');
+	out.print(']');
     }
 
     /**
      * Integers are printed in decimal.
      */
     private void print(int i) {
-	out.print(" ");
+	out.print(' ');
+	dump(i);
+    }
+    private void dump(int i) {
 	out.print(i);
     }
-    private void print(int[] a) {
-	out.print(" [");
+    private void dump(int[] a) {
+	out.print('[');
 	for (int i = 0; i < a.length; i++) {
 	    if (i > 0)
-		out.print(",");
-	    out.print(a[i]);
+		out.print(',');
+	    dump(i);
 	}
-	out.print("]");
+	out.print(']');
     }
 
     /**
      * Longs are printed in hex.
      */
     private void print(long l) {
-	out.print(" 0x");
-	out.print(Long.toHexString(l));
+	out.print(' ');
+	dump(l);
     }
-    private void print(long[] a) {
-	out.print(" [");
+    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(",");
-	    out.print("0x");
-	    out.print(Long.toHexString(a[i]));
+		out.print(',');
+	    dump(a[i]);
 	}
-	out.print("]");
+	out.print(']');
     }
+
     /**
      * Strings are just copied.
      */
@@ -316,20 +348,15 @@ public final class Log {
 	    return;
 	prefix(); print(p1); print(p2); suffix();
     }
-    public void log(String p1, char[] p2) {
+    public void log(String p1, Object p2) {
 	if (!logging)
 	    return;
 	prefix(); print(p1); print(p2); suffix();
     }
     public void log(String p1, String p2) {
-	if (!logging)
-	    return;
-	prefix(); print(p1); print(p2); suffix();
-    }
-    public void log(String p1, Object p2) {
-	if (!logging)
-	    return;
-	prefix(); print(p1); print(p2); suffix();
+	// Needed to disambiguate log(String,String) which could be
+	// either log(Object,String) or log(String,Object).
+	log(p1, (Object)p2);
     }
     public void log(String p1, Object p2, String p3) {
 	if (!logging)
@@ -368,26 +395,11 @@ public final class Log {
 	    return;
 	prefix(self); print(p1); print(p2); suffix();
     }
-    public void log(Object self, String p1, String p2) {
-	if (!logging)
-	    return;
-	prefix(self); print(p1); print(p2); suffix();
-    }
     public void log(Object self, String p1, Object p2) {
 	if (!logging)
 	    return;
 	prefix(self); print(p1); print(p2); suffix();
     }
-    public void log(Object self, String p1, int[] p2) {
-	if (!logging)
-	    return;
-	prefix(self); print(p1); print(p2); suffix();
-    }
-    public void log(Object self, String p1, long[] p2) {
-	if (!logging)
-	    return;
-	prefix(self); print(p1); print(p2); suffix();
-    }
     public void log(Object self, String p1, int p2, String p3, char p4) {
 	if (!logging)
 	    return;
diff --git a/frysk-sys/frysk/rsl/package.html b/frysk-sys/frysk/rsl/package.html
index 01e98fe..dadf71b 100644
--- a/frysk-sys/frysk/rsl/package.html
+++ b/frysk-sys/frysk/rsl/package.html
@@ -40,9 +40,9 @@ formatted as follows:
 
 <table border=1>
 <tr><th>Type</th><th>Format</th></tr>
+<tr><td>char</td><td>The character in single quotes</td></tr>
 <tr><td>int</td><td>Signed Decimal</td></tr>
 <tr><td>long</td><td>Unsigned Hexadecimal</td></tr>
-<tr><td>String</td><td>The string (unquoted)</td></tr>
 <tr><td>Object</td><td>
 <table>
 <tr><td>Throwable</td><td>The throwable's and all causes's getMessage() wraped in &lt;&lt; &gt;&gt;</td></tr>
@@ -56,12 +56,12 @@ formatted as follows:
 for instance:
 
 <pre>
-logger.log("int", 1, "long", (long)1, "string", "foo", "object", (Object)"\t");
-... int 1 long 0x1 string foo object "\t"
+logger.log("int", 1, "long", (long)1, "string", "foo\t");
+... int 1 long 0x1 string "foo\t"
 </pre>
 
-(notice how casting can be used to select between specific format.
-For instance "int" and "long", and "String" and "Object").
+(notice how casting can be used to select between decimal (int) and
+hex (long) specific formats.
 
 <h2>Command Line Option Syntax</h2>
 


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


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

only message in thread, other threads:[~2008-02-11 19:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-11 19:44 [SCM] master: Simplify log output formatting 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).