public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* a simpler logger [?]
@ 2007-12-07 16:37 Andrew Cagney
  2007-12-17 20:05 ` Andrew Cagney
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2007-12-07 16:37 UTC (permalink / raw)
  To: frysk

Hi,

I've just added a frysk.rsl (really simple logger?) package as a 
possible alternative to the java logging framework we're currently 
using.  The "advantages" as I'll spin them are:

-> the logging call is unlocked (at least in the logger level)
so the ongoing saga of older log implementations deadlocking is avoided

-> nested logging works

-> it supports a completer interface
so that << (fhpd) frysk log frysk.proc.<TAB> >> can give a known list of 
loggers

-> [I think] the call interface is simpler and lighter
for instance << log.fine(this, "adding foo") >> or << log.fine(this, 
"adding foo=", foo); >> (we can add more methods as we need them :-)

thoughts?

Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: a simpler logger [?]
  2007-12-07 16:37 a simpler logger [?] Andrew Cagney
@ 2007-12-17 20:05 ` Andrew Cagney
  2008-02-11 18:52   ` Andrew Cagney
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2007-12-17 20:05 UTC (permalink / raw)
  To: frysk

FYI,

I've marked up frysk.expunit to use this logger (so people can see it 
working).  Enable it with something like:
   ./TestRunner -trace FINE frysk.hpd.TestLoadCommand
or:
  ./TtestRunner -trace frysk.expunit=FINEST  frysk.hpd.TestLoadCommand

Andrew

Andrew Cagney wrote:
> Hi,
>
> I've just added a frysk.rsl (really simple logger?) package as a 
> possible alternative to the java logging framework we're currently 
> using.  The "advantages" as I'll spin them are:
>
> -> the logging call is unlocked (at least in the logger level)
> so the ongoing saga of older log implementations deadlocking is avoided
>
> -> nested logging works
>
> -> it supports a completer interface
> so that << (fhpd) frysk log frysk.proc.<TAB> >> can give a known list 
> of loggers
>
> -> [I think] the call interface is simpler and lighter
> for instance << log.fine(this, "adding foo") >> or << log.fine(this, 
> "adding foo=", foo); >> (we can add more methods as we need them :-)
>
> thoughts?
>
> Andrew
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: a simpler logger [?]
  2007-12-17 20:05 ` Andrew Cagney
@ 2008-02-11 18:52   ` Andrew Cagney
  2008-02-12 12:15     ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2008-02-11 18:52 UTC (permalink / raw)
  To: frysk

FYI,

Much of frysk-sys is now using this logger; in switching my stack-smash 
bug seems to have gone back into hiding, sigh :-(

In using this logger, I've also made the following refinements:

-> The option is renamed to << -debug <what> >> rather than << -trace 
<what> >>; "trace" gets confusing when using tools such as ftrace (I'm 
not sure that -debug is much better though :-)

-> The option parser is far more (far too?) forgiving in what it 
accepts; for instance:
     -debug frysk.expunit                          -- default to level FINE
     -debug frysk.expunit=FINEST         -- explicit
     -debug FINE                                        -- global

-> The logger understands class inheritance - explicitly setting a super 
classes log-level automatically updates all sub-classes; for instance:
     -debug frysk.junit.TestCase             -- enables logging for all 
instances of TestCase including sub-classes.

Andrew

  
Andrew Cagney wrote:
> FYI,
>
> I've marked up frysk.expunit to use this logger (so people can see it 
> working).  Enable it with something like:
>   ./TestRunner -trace FINE frysk.hpd.TestLoadCommand
> or:
>  ./TtestRunner -trace frysk.expunit=FINEST  frysk.hpd.TestLoadCommand
>
> Andrew
>
> Andrew Cagney wrote:
>> Hi,
>>
>> I've just added a frysk.rsl (really simple logger?) package as a 
>> possible alternative to the java logging framework we're currently 
>> using.  The "advantages" as I'll spin them are:
>>
>> -> the logging call is unlocked (at least in the logger level)
>> so the ongoing saga of older log implementations deadlocking is avoided
>>
>> -> nested logging works
>>
>> -> it supports a completer interface
>> so that << (fhpd) frysk log frysk.proc.<TAB> >> can give a known list 
>> of loggers
>>
>> -> [I think] the call interface is simpler and lighter
>> for instance << log.fine(this, "adding foo") >> or << log.fine(this, 
>> "adding foo=", foo); >> (we can add more methods as we need them :-)
>>
>> thoughts?
>>
>> Andrew
>>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: a simpler logger [?]
  2008-02-11 18:52   ` Andrew Cagney
@ 2008-02-12 12:15     ` Mark Wielaard
  2008-02-12 12:23       ` Phil Muldoon
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Wielaard @ 2008-02-12 12:15 UTC (permalink / raw)
  To: frysk

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: a simpler logger [?]
  2008-02-12 12:15     ` Mark Wielaard
@ 2008-02-12 12:23       ` Phil Muldoon
  2008-02-12 13:29         ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Phil Muldoon @ 2008-02-12 12:23 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: frysk

Mark Wielaard wrote:
> 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:
>   

This is useful because I can now see what is calling the function,  from 
the rsl log call:

    fine.log(this,"getAuxv()",fine.caller());

produces (from an actual log output) below.

0 00:00:00.086  [{frysk.proc.dead.LinuxCoreProc@2f8ad3b5,pid=18314,state=dead}]: getAuxv() "frysk.dwfl.DwflFactory.VDSOAddressLow(fstack)"


As fine.caller() is an optional call (you have to supply it in the 
arguments), the overhead of the Throwable can be managed by the 
programmer. Personally I find it immensely useful to detect the origin 
of a call. I would like to see it the Log code.

Regards

Phil

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: a simpler logger [?]
  2008-02-12 12:23       ` Phil Muldoon
@ 2008-02-12 13:29         ` Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2008-02-12 13:29 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: frysk

[-- Attachment #1: Type: text/plain, Size: 444 bytes --]

Hi Phil,

On Tue, 2008-02-12 at 12:23 +0000, Phil Muldoon wrote:
> As fine.caller() is an optional call (you have to supply it in the 
> arguments), the overhead of the Throwable can be managed by the 
> programmer. Personally I find it immensely useful to detect the origin 
> of a call. I would like to see it the Log code.

Thanks. Attached is what I will most likely push, unless you find any
troubles while testing with it.

Cheers,

Mark

[-- Attachment #2: Log-caller.patch --]
[-- Type: text/x-patch, Size: 3535 bytes --]

commit d9c5abf617a6157c7df7db340f8f9fdb9b42e538
Author: Mark Wielaard <mwielaard@redhat.com>
Date:   Tue Feb 12 14:18:08 2008 +0100

    Add caller() and callers() methods to rsl Log.
    
    frysk-sys/frysk/rsl/ChangeLog
    2008-02-12  Mark Wielaard  <mwielaard@redhat.com>
    
            * Log.java (caller): New public method.
            (empty): New private empty String[].
            (callersArray): New private method.
            (callers): New public method.
            (callers(int)): New public method.

diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog
index a2997cf..2b84755 100644
--- a/frysk-sys/frysk/rsl/ChangeLog
+++ b/frysk-sys/frysk/rsl/ChangeLog
@@ -1,3 +1,11 @@
+2008-02-12  Mark Wielaard  <mwielaard@redhat.com>
+
+	* Log.java (caller): New public method.
+	(empty): New private empty String[].
+	(callersArray): New private method.
+	(callers): New public method.
+	(callers(int)): New public method.
+
 2008-02-11  Andrew Cagney  <cagney@redhat.com>
 
 	* Log.java (prefixTime()): Print time in DAY HH:MM:SS.mmm format;
diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Log.java
index 1ddfa73..e77aaed 100644
--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Log.java
@@ -420,4 +420,75 @@ public final class Log {
 	    return;
 	prefix(self); print(p1); print(p2); print(p3); print(p4); print(p5); print(p6); suffix();
     }
+
+  /**
+   * 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>";
+  }
+
+  // Empty caller array for use in callersArray.
+  static private final String[] empty = new String[0];
+
+  // Private method that should only be directly called from
+  // callers() or callers(int), which in turn should only be called
+  // directly from the method that uses the Log and wants to find
+  // its callers. Depends on actual caller being of depth 3.
+  private String[] callersArray(int max)
+  {
+    if (logging)
+      {
+        Throwable t = new Throwable();
+        StackTraceElement[] stackTrace = t.getStackTrace();
+	int length = stackTrace.length > 3 ? stackTrace.length - 3 : 0;
+	if (length > max)
+	  length = max;
+	String[] callers = new String[length];
+        while (length > 0)
+	  {
+	    callers[length - 1]
+	      = stackTrace[length + 2].toString();
+	    length--;
+	  }
+	return callers;
+      }
+
+    return empty;
+  }
+
+  /**
+   * Convenience method to get an array of callers of a method in
+   * which you use the Log object. Returns the callers (of the caller)
+   * of this method as a String[] or an empty array if the callers
+   * cannot be found or if logger isn't logging. Use as:
+   * <code>log.log(this, "method called by ", log.callers());</code>.
+   * This is pretty heavyweight when the Log is enabled, so use
+   * sparingly.
+   */
+  public String[] callers()
+  {
+    return callersArray(Integer.MAX_VALUE);
+  }
+
+  /**
+   * Same as callers() but only returns at most max callers.
+   */
+  public String[] callers(int max)
+  {
+    return callersArray(max);
+  }
 }

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-02-12 13:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-07 16:37 a simpler logger [?] Andrew Cagney
2007-12-17 20:05 ` Andrew Cagney
2008-02-11 18:52   ` Andrew Cagney
2008-02-12 12:15     ` Mark Wielaard
2008-02-12 12:23       ` Phil Muldoon
2008-02-12 13:29         ` Mark Wielaard

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).