public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Permit customized logging.
@ 2008-02-26 14:19 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-02-26 14:19 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  7174ba407d72d790645f20a5db9682dd142bd772 (commit)
      from  b1e43dbc905f9ab3aa3e20e6f4cd9645823d7367 (commit)

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

- Log -----------------------------------------------------------------
commit 7174ba407d72d790645f20a5db9682dd142bd772
Author: Andrew Cagney <cagney@redhat.com>
Date:   Tue Feb 26 09:18:46 2008 -0500

    Permit customized logging.
    
    frysk-sys/frysk/rsl/ChangeLog
    2008-02-26  Andrew Cagney  <cagney@redhat.com>
    
    	* package.html (Implementing a Custom Log): New.
    	* Log.java (prefix, print): Return Log.  Make public.

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

Summary of changes:
 frysk-sys/frysk/rsl/ChangeLog    |    5 +
 frysk-sys/frysk/rsl/Log.java     |  156 +++++++++++++++++++------------------
 frysk-sys/frysk/rsl/package.html |   13 +++
 3 files changed, 98 insertions(+), 76 deletions(-)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog
index 73b33c2..5110360 100644
--- a/frysk-sys/frysk/rsl/ChangeLog
+++ b/frysk-sys/frysk/rsl/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-26  Andrew Cagney  <cagney@redhat.com>
+
+	* package.html (Implementing a Custom Log): New.
+	* Log.java (prefix, print): Return Log.  Make public.
+
 2008-02-20  Andrew Cagney  <cagney@redhat.com>
 
 	* Log.java: Include the TID.PID in the log message.
diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Log.java
index 0a3e3eb..043b3ee 100644
--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Log.java
@@ -160,62 +160,34 @@ public final class Log {
 	out.print(' ');
     }
 
-    private void prefix() {
+    public Log prefix() {
 	prefixTimeAndPid();
 	out.print(path);
 	out.print(":");
+	return this;
     }
 
-    private void prefix(Object o) {
+    public Log prefix(Object o) {
 	prefixTimeAndPid();
 	out.print("[");
 	out.print(o.toString());
 	out.print("]:");
+	return this;
     }
 
-    private void suffix() {
+    public void suffix() {
 	out.println();
 	out.flush();
     }
   
     /**
-     * Throwables get their message printed; along with any root
-     * causes.
-     */
-    private void dump(Throwable t) {
-	out.print("<<exception");
-	Throwable cause = t;
-	do {
-	    out.print(":");
-	    out.print(t.getMessage());
-	    cause = cause.getCause();
-	} while (cause != null);
-	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
+     * Use poorly implemented reflection to dump Objects.
      */
-    private void dump(Object o, int i) {
-	// for moment assume the array contains Objects; dump recursively.
-	dump(Array.get(o, i));
+    public Log print(Object o) {
+	out.print(' ');
+	dump(o);
+	return this;
     }
-    /**
-     * Dump an arbitrary object.
-     * @param o the object to dump
-     */
     private void dump(Object o) {
 	if (o == null) {
 	    out.print("<<null>>");
@@ -246,19 +218,47 @@ public final class Log {
 	}
     }
     /**
-     * Use poorly implemented reflection to dump Objects.
+     * Throwables get their message printed; along with any root
+     * causes.
      */
-    private void print(Object o) {
-	out.print(' ');
-	dump(o);
+    private void dump(Throwable t) {
+	out.print("<<exception");
+	Throwable cause = t;
+	do {
+	    out.print(":");
+	    out.print(t.getMessage());
+	    cause = cause.getCause();
+	} while (cause != null);
+	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.
      */
-    private void print(boolean b) {
+    public Log print(boolean b) {
 	out.print(' ');
 	dump(b);
+	return this;
     }
     private void dump(boolean b) {
 	out.print(b);
@@ -276,9 +276,10 @@ public final class Log {
     /**
      * Chars are printed in quotes.
      */
-    private void print(char c) {
+    public Log print(char c) {
 	out.print(' ');
 	dump(c);
+	return this;
     }
     private void dump(char c) {
 	out.print('\'');
@@ -298,9 +299,10 @@ public final class Log {
     /**
      * Integers are printed in decimal.
      */
-    private void print(int i) {
+    public Log print(int i) {
 	out.print(' ');
 	dump(i);
+	return this;
     }
     private void dump(int i) {
 	out.print(i);
@@ -318,9 +320,10 @@ public final class Log {
     /**
      * Longs are printed in hex.
      */
-    private void print(long l) {
+    public Log print(long l) {
 	out.print(' ');
 	dump(l);
+	return this;
     }
     private void dump(long l) {
 	out.print("0x");
@@ -340,9 +343,10 @@ public final class Log {
     /**
      * Strings are just copied.
      */
-    private void print(String s) {
+    public Log print(String s) {
 	out.print(" ");
 	out.print(s);
+	return this;
     }
     
     /**
@@ -370,34 +374,34 @@ public final class Log {
     public void log(String p1) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); suffix();
+	prefix().print(p1).suffix();
     }
 
     // static 2 parameters
     public void log(String p1, boolean p2) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); suffix();
+	prefix().print(p1).print(p2).suffix();
     }
     public void log(String p1, char p2) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); suffix();
+	prefix().print(p1).print(p2).suffix();
     }
     public void log(String p1, int p2) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); suffix();
+	prefix().print(p1).print(p2).suffix();
     }
     public void log(String p1, long p2) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); suffix();
+	prefix().print(p1).print(p2).suffix();
     }
     public void log(String p1, Object p2) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); suffix();
+	prefix().print(p1).print(p2).suffix();
     }
     public void log(String p1, String p2) {
 	// Needed to disambiguate log(String,String) which could be
@@ -409,41 +413,41 @@ public final class Log {
     public void log(String p1, Object p2, String p3) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); print(p3); suffix();
+	prefix().print(p1).print(p2).print(p3).suffix();
     }
 
     // static 4 parameters
     public void log(String p1, int p2, String p3, Object p4) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); print(p3); print(p4); suffix();
+	prefix().print(p1).print(p2).print(p3).print(p4).suffix();
     }
     public void log(String p1, long p2, String p3, int p4) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); print(p3); print(p4); suffix();
+	prefix().print(p1).print(p2).print(p3).print(p4).suffix();
     }
     public void log(String p1, Object p2, String p3, long p4) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); print(p3); print(p4); suffix();
+	prefix().print(p1).print(p2).print(p3).print(p4).suffix();
     }
     public void log(String p1, Object p2, String p3, Object p4) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); print(p3); print(p4); suffix();
+	prefix().print(p1).print(p2).print(p3).print(p4).suffix();
     }
 
     // static 8 parameters
     public void log(String p1, Object p2, String p3, Object p4, String p5, Object p6, String p7, Object p8) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); print(p7); print(p8); suffix();
+	prefix().print(p1).print(p2).print(p3).print(p4).print(p5).print(p6).print(p7).print(p8).suffix();
     }
     public void log(String p1, int p2, String p3, Object p4, String p5, Object p6, String p7, Object p8) {
 	if (!logging)
 	    return;
-	prefix(); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); print(p7); print(p8); suffix();
+	prefix().print(p1).print(p2).print(p3).print(p4).print(p5).print(p6).print(p7).print(p8).suffix();
     }
     
     // Non-static log methods; first parameter is the object.
@@ -452,96 +456,96 @@ public final class Log {
     public void log(Object self, String p1) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); suffix();
+	prefix(self).print(p1).suffix();
     }
 
     // dynamic 2 parameters
     public void log(Object self, String p1, int p2) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); suffix();
+	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();
+	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();
+	prefix(self).print(p1).print(p2).suffix();
     }
 
     // dynamic 3 parameters
     public void log(Object self, String p1, Object p2, String p3) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); suffix();
+	prefix(self).print(p1).print(p2).print(p3).suffix();
     }
 
     // dynamic 4 parameters
     public void log(Object self, String p1, boolean p2, String p3, int p4) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).suffix();
     }
     public void log(Object self, String p1, int p2, String p3, char p4) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).suffix();
     }
     public void log(Object self, String p1, Object p2, String p3, Object p4) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).suffix();
     }
     public void log(Object self, String p1, Object p2, String p3, int p4) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).suffix();
     }
 
     // dynamic 5 parameters
     public void log(Object self, String p1, Object p2, String p3, long p4, String p5) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).print(p5).suffix();
     }
 
     // dynamic 6 parameters
     public void log(Object self, String p1, Object p2, String p3, long p4, String p5, long p6) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).print(p5).print(p6).suffix();
     }
     public void log(Object self, String p1, Object p2, String p3, Object p4, String p5, int p6) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).print(p5).print(p6).suffix();
     }
     public void log(Object self, String p1, Object p2, String p3, Object p4, String p5, Object p6) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).print(p5).print(p6).suffix();
     }
 
     // dynamic 9 parameters
     public void log(Object self, String p1, Object p2, String p3, long p4, String p5, int p6, String p7, int p8, String p9) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); print(p7); print(p8); print(p9); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).print(p5).print(p6).print(p7).print(p8).print(p9).suffix();
     }
     public void log(Object self, String p1, Object p2, String p3, long p4, String p5, long p6, String p7, int p8, String p9) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); print(p7); print(p8); print(p9); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).print(p5).print(p6).print(p7).print(p8).print(p9).suffix();
     }
 
     // dynamic 11 parameters
     public void log(Object self, String p1, Object p2, String p3, long p4, String p5, Object p6, String p7, int p8, String p9, int p10, String p11) {
 	if (!logging)
 	    return;
-	prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); print(p7); print(p8); print(p9); print(p10); print(p11); suffix();
+	prefix(self).print(p1).print(p2).print(p3).print(p4).print(p5).print(p6).print(p7).print(p8).print(p9).print(p10).print(p11).suffix();
     }
 
 
diff --git a/frysk-sys/frysk/rsl/package.html b/frysk-sys/frysk/rsl/package.html
index dadf71b..a9e5327 100644
--- a/frysk-sys/frysk/rsl/package.html
+++ b/frysk-sys/frysk/rsl/package.html
@@ -91,6 +91,19 @@ For instance:
 A completer is available for command-lines wanting to provide
 tab-completion of the known set of loggers.
 
+<h2>Implementing a Custom Log</h2>
+
+Sometimes the data that needs to be printed is just too wierd a
+sequence to justify the addition of an additional log method.  For
+those cases, a custom log sequence can be implemented vis:
+
+<pre>
+Log fine = ...;
+...
+if (fine.logging())
+  fine.prefix(this).print("why arg").print(arg).suffix();
+</pre>
+
 <h2>Comparison with Existing Loggers</h2>
 
 The following differences between this logger and <tt>log4j</tt>


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


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

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

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-26 14:19 [SCM] master: Permit customized logging 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).