Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Classy logging for Classes

4 views
Skip to first unread message

szba...@inf.elte.hu

unread,
Jun 22, 2006, 1:19:47 PM6/22/06
to perl6-l...@perl.org
I'm trying to collect ideas about how could be (optionally available)
logging added/implemented for classes, as in logging what methods are
called at runtime, the parameters they are called with, etc. without
embedding the whole logic in the methods themselves on a one-by-one basis.

What I'm specifically looking for would be an instance based idea, so it
doesn't permanently overwrite the class and thus consequently switch
logging on everywhere that class is used, only for the scope of a given
instance of the class.

This separation/factoring out logging from a class would provide more
elegant and cleaner code, for example by not requiring a method
dispatcher capable of logging. The question is, how can it be done?

Please share your thoughts and ideas on this issue.


Thank you in advance,

Balint Szilakszi [english spelling]
Szilakszi Bálint [hungarian spelling]

Yuval Kogman

unread,
Jun 22, 2006, 1:25:25 PM6/22/06
to Szilakszi Bálint, perl6-l...@perl.org
On Thu, Jun 22, 2006 at 19:19:47 +0200, Szilakszi Bálint wrote:
> I'm trying to collect ideas about how could be (optionally available) logging added/implemented for classes, as in logging what methods are called at runtime, the parameters they are called
> with, etc. without embedding the whole logic in the methods themselves on a one-by-one basis.

When the meta object protocol is exposed this will likely be a very
simple meta-class mixin role.

> What I'm specifically looking for would be an instance based idea, so it doesn't permanently overwrite the class and thus consequently switch logging on everywhere that class is used, only for
> the scope of a given instance of the class.

This can probably be hacked at runtime by reblessing the object into
a temporarily role-mixed meta class.

That said, most of the useful logging i've seen is not automatically
generated. Traces are easy to do like this, but high quality logs
should be hand rolled so that they convey the most meaningful
representation of information.

For this, aspect oriented programming can help you separate the
logging from the actual body of the method, but this is not always
the most "correct" behavior.

--
Yuval Kogman <nothi...@woobling.org>
http://nothingmuch.woobling.org 0xEBD27418

0 new messages