Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2003

Tip: Looking for answers? Try searching our database.

Automatic generation of entrance and exit logging

Thread view: 
Chishun Kwong - 15 Sep 2003 21:14 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.