From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7228 invoked by alias); 11 Feb 2008 19:44:24 -0000 Received: (qmail 7200 invoked by uid 367); 11 Feb 2008 19:44:24 -0000 Date: Mon, 11 Feb 2008 19:44:00 -0000 Message-ID: <20080211194424.7185.qmail@sourceware.org> From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Simplify log output formatting. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 9217bc52ea47dd010f68d87426a70b491cbf4689 X-Git-Newrev: af5efc444c59457e9a2f9b77382ddd6073ee4edc Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2008-q1/txt/msg00193.txt.bz2 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 Date: Mon Feb 11 14:43:11 2008 -0500 Simplify log output formatting. frysk-sys/frysk/rsl/ChangeLog 2008-02-11 Andrew Cagney * 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 + * 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: + -
TypeFormat
charThe character in single quotes
intSigned Decimal
longUnsigned Hexadecimal
StringThe string (unquoted)
Object @@ -56,12 +56,12 @@ formatted as follows: for instance:
-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"
 
-(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.

Command Line Option Syntax

hooks/post-receive -- frysk system monitor/debugger
ThrowableThe throwable's and all causes's getMessage() wraped in << >>