public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: frysk <frysk@sourceware.org>
Subject: Re: a simpler logger [?]
Date: Tue, 12 Feb 2008 12:15:00 -0000	[thread overview]
Message-ID: <1202818497.3378.8.camel@dijkstra.wildebeest.org> (raw)
In-Reply-To: <47B09909.4070707@redhat.com>

Hi,

While helping Phil figuring out what part of his code was called (over
and over again) from where we came up with the following small extension
of the rsl:

--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Log.java
@@ -420,4 +420,24 @@ public final class Log {
            return;
        prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); pri
     }
+
+  /**
+   * Convenience method to get the caller of a method in which you
+   * use the Log object. Returns the caller (of the caller) of this
+   * method as String or "<unknown>" if caller cannot be found or if
+   * logger isn't logging. Use as:
+   * <code>log.log(this, "method called by ", log.caller());</code>.
+   */
+  public String caller()
+  {
+    if (logging)
+      {
+       Throwable t = new Throwable();
+       StackTraceElement[] stackTrace = t.getStackTrace();
+       if (stackTrace.length > 2)
+         return stackTrace[2].toString();
+      }
+
+    return "<unknown>";
+  }
 }

It was pretty useful so I would like to add it unless someone objects to
bloating the really simple logger. Maybe also with a variant that gives
the whole call stack (but again only creates it when logging of course).

Cheers,

Mark

  reply	other threads:[~2008-02-12 12:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-07 16:37 Andrew Cagney
2007-12-17 20:05 ` Andrew Cagney
2008-02-11 18:52   ` Andrew Cagney
2008-02-12 12:15     ` Mark Wielaard [this message]
2008-02-12 12:23       ` Phil Muldoon
2008-02-12 13:29         ` Mark Wielaard

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=1202818497.3378.8.camel@dijkstra.wildebeest.org \
    --to=mark@klomp.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).