Ceki, 
So far as I've seen (aside from AspectJ, which I shied away from because of
the precompiler "voodoo" nature) there is not any *totally* non intrusive
way.  

If you do not have the luxory of a factory that you can do the constructor
interception at, you can do a search and replace style thingie where you:

Replace:        "= new " + * + ");"
with:           "= new DebugProxy.for( " + * + ") );"

So:             FooBarClass fb = new FooBarClass(myargs);
Becomes:        FooBarClass fb = DebugProxy.for( new FooBarClass(myargs) );

And the DebugProxy class is a static class whose .for() method accepts an
object, wraps it in a Proxy and then returns it. (typically only wrapping it
if a debug flag is set.)

Unfortunatly this uglifies your code a bit, but if you do not have a
factory...  You can tweak the DebugProxy.for method to only wrap certain
classes, etc.

In a way I'd like to see something like this added to log4j's varia package.
I mean it *is* kinda neat (and useful too!)


Regards

John Volkar


-----Original Message-----
From: Ceki Gülcü [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 22, 2001 10:51 AM
To: LOG4J Users Mailing List
Subject: RE: wrapper for Log4j for method entrance/exit?




At 10:43 22.03.2001 -0500, you wrote:
>The non-intrusive, "more than you could ever hope for" solution for this
and
>others like it is AspectJ.  www.aspectj.org  The primary disadvantage is
>that it's a precompiler.

Jim,

...which is also its primary disadvantage! How easy do you think is to find
errors in aspectj generated code? I suspect it is not easy. Otherwise,
aspectj is pretty interesting technology to say the least. Ceki

>-Jim Moore
>
>-----Original Message-----
>From: Ceki Gülcü [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, March 22, 2001 10:12 AM
>To: LOG4J Users Mailing List
>Subject: RE: wrapper for Log4j for method entrance/exit?
>
>
>
>John,
>
>Thanks for the pointer. Neat idea. One comment though: the approach is
>intrusive in the sense that instantiation for objects to be traced at the
>method level must be performed by a factory class (or method) not by a
>constructor. This is a non-negligible restriction.. Can it be circumvented?
>Thanks again, Ceki    
>
>At 09:34 22.03.2001 -0500, you wrote:
>>Alex,
>>
>>I don't beleive that there is anything like this built into Log4j.  You
can
>>fairly easily do it yourself though.  Rather than describe it here I'll
>just
>>point to in the right direction.
>>
>>Take a look at the Proxy & InvokationHandler classes.  NOTE: This is only
>>available with JDK 1.3 I believe.  If you've followed a factory pattern
>this
>>is easy to implement.  If not (if you just go and "new FooBarClass()"
>>directly you'll have more work to do.
>>
>>Hmm, there was an article that described this, wait a minute...  Okay: the
>>article's name is "Friction Free Debuging with Proxies" it at:
>>http://www.java-pro.com/upload/free/features/javapro/2000/11nov00/jm0011/j
m
>0
>>011.asp
>>
>>It doen't use Log4j, but it's easy enough to alter.  Take your time and
>read
>>it, it's not too difficult to follow.  There are some caveats to using it
>>('this' pointer related)  but nothing dreadful. (Except performance!)
>>
>>
>>Hope this helps
>>
>>John Volkar
>>Senior Software Engineer II
>>E-Transport, a division of Descartes (DSGX)
>>[EMAIL PROTECTED]
>>
>>
>>-----Original Message-----
>>From: Alex Colic [mailto:[EMAIL PROTECTED]]
>>Sent: Thursday, March 22, 2001 9:18 AM
>>To: [EMAIL PROTECTED]
>>Subject: wrapper for Log4j for method entrance/exit?
>>
>>
>>Hi,
>>
>>I am adding more debugging to my app. As my program runs I would like to
>>print to a file as it enters methods and exits them. I know that at the
>>beginning of the method and at the end I could do something like
>>
>>log("Entered method: MyMethod()");
>>
>>but that would be tedious.
>>
>>Is there some time of wrapper class that I could pass the class to in a
>>constructor that as methods in the class are called, logging occurs?
>>
>>Thanks for any help.
>>
>>Alex
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]


I hope to see you at my ApacheCon 2001 presentation 
entitled "Log4j, A Logging Package for Java".

See http://ApacheCon.Com/2001/US/ for more details.

----
Ceki Gülcü          Web:   http://qos.ch     
av. de Rumine 5     email: [EMAIL PROTECTED] (preferred)
CH-1005 Lausanne           [EMAIL PROTECTED]
Switzerland         Tel: ++41 21 351 23 15


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to