Hello,
I have a need to add entrance and exit logging to all the public
methods of all classes of a certain package. While I don't have that
many of them and putting the logging in manually is an option, I am
wondering if there is a better way.
I am thinking of using the doclet api to discover what a class is
consist of and then "reconstruct" the source file, adding the logging
along the way, and then recompile it. For example, after learning that
I have a method that looks like this
public int getACertainNumber ()
{
< method body >
}
I will recreate the method, but add the logging, like this
public int getACertainNumber ()
{
Logger.getInstance.log("Entered getACertainNumber");
try {
< method body >
} finally {
Logger.getInstance.log("Exited getACertainNumber");
}
}
I know in advance that all my classes are simple enough that I don't
have to worry about special things like static initializers and inner
classes, however, even with this, I find this impossible to do with
the doclet api because it does not give me the method body.
Does anyone know a tool comparable to javadoc/doclet that will give me
the method body in addition to the class's metadata? Alternatively,
any suggestion to tackle this problem? I am sure someone must have
done this before.
I really think this is a better way to approach this problem because
it is much easier to maintain, and I can turn off the logging
altogether (they are for performance analysis only).
Thanks for any suggestion,
Chishun Kwong.
Christophe Vanfleteren - 15 Sep 2003 22:59 GMT
> Hello,
>
[quoted text clipped - 41 lines]
> Thanks for any suggestion,
> Chishun Kwong.
checkout http://just4log.sourceforge.net/
It can add the entry/exit method log calls in the compiled classes.

Signature
mvg,
Christophe Vanfleteren
Eduardo Francos - 17 Sep 2003 02:03 GMT
Chishun Kwong wrote on 09/15/2003 10:14 PM:
> Hello,
>
[quoted text clipped - 41 lines]
> Thanks for any suggestion,
> Chishun Kwong.
Take a look at Aspect Oriented Programming AOP. I use AspectJ
(http://eclipse.org/aspectj/).
It can do much more, but one of its most common uses is exactly to solve
the problem you describe.
Eduardo