C
Chishun Kwong
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.
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.