public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Permit customized logging. Date: Tue, 26 Feb 2008 14:19:00 -0000 [thread overview] Message-ID: <20080226141932.7442.qmail@sourceware.org> (raw) 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
reply other threads:[~2008-02-26 14:19 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=20080226141932.7442.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: linkBe 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).