From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13822 invoked by alias); 12 Feb 2008 12:15:18 -0000 Received: (qmail 13814 invoked by uid 22791); 12 Feb 2008 12:15:17 -0000 X-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_50 X-Spam-Check-By: sourceware.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (83.160.170.119) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 12 Feb 2008 12:15:00 +0000 Received: from dijkstra.wildebeest.org ([192.168.1.29]) by gnu.wildebeest.org with esmtp (Exim 4.63) (envelope-from ) id 1JOu2L-00040m-Kc for frysk@sourceware.org; Tue, 12 Feb 2008 13:14:58 +0100 Subject: Re: a simpler logger [?] From: Mark Wielaard To: frysk In-Reply-To: <47B09909.4070707@redhat.com> References: <475976DF.6070302@redhat.com> <4766D650.6080102@redhat.com> <47B09909.4070707@redhat.com> Content-Type: text/plain Date: Tue, 12 Feb 2008 12:15:00 -0000 Message-Id: <1202818497.3378.8.camel@dijkstra.wildebeest.org> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 (2.12.3-1.fc8) Content-Transfer-Encoding: 7bit X-Spam-Score: -4.4 (----) X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2008-q1/txt/msg00060.txt.bz2 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 "" if caller cannot be found or if + * logger isn't logging. Use as: + * log.log(this, "method called by ", log.caller());. + */ + public String caller() + { + if (logging) + { + Throwable t = new Throwable(); + StackTraceElement[] stackTrace = t.getStackTrace(); + if (stackTrace.length > 2) + return stackTrace[2].toString(); + } + + return ""; + } } 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