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 / February 2006

Tip: Looking for answers? Try searching our database.

Logging method information

Thread view: 
Bo Rasmussen - 16 Feb 2006 11:04 GMT
Hi,

I'm looking for a general way to log calls to an API. In the start of every
method on the API I would like to log the name of the method and all
parameters passed. Can that be done - I know that in log4J it is possible to
output the method name, but I would like to log more than that. Any help is
appreciated.

Kind regards
Bo Rasmussen
Vitamines - 16 Feb 2006 12:46 GMT
you should add the parameters to log4j which you are interested in
then set log4j to different level
during coding,set the level "debug"
when running ,set the level "warn"
Bo Rasmussen - 16 Feb 2006 13:03 GMT
The problem is that I would like to output complete information about the
method call - not just the method name. afaik the only parameter for a
PatternLayout is M, which makes log4j output the method name. This is
however not sufficient as I need both the method name and the passed
parameters.

Kind regards
Bo Rasmussen

> you should add the parameters to log4j which you are interested in
> then set log4j to different level
> during coding,set the level "debug"
> when running ,set the level "warn"
_weijiang_@yahoo.com - 16 Feb 2006 13:00 GMT
Try SuperLogging from
http://www.acelet.com/super/SuperLogging/index.html.
It logs whereas information as well. You can dynamically reconfigre
everything.
It is free.

> Hi,
>
[quoted text clipped - 6 lines]
> Kind regards
> Bo Rasmussen
Chris Uppal - 16 Feb 2006 14:50 GMT
> I'm looking for a general way to log calls to an API. In the start of
> every method on the API I would like to log the name of the method and all
> parameters passed. Can that be done

I can't be done without considerable complexity -- the Java runtime doesn't
give you reflective access to the parameter values as it does to the method
names.

You /could/ do it by pre-processing your Java source files to include full
logging information automatically, or you could indulge in some bytecode
rewriting to include the equivalent at runtime.  Its hard to see either course
being worth the effort, though, unless you can find a pre-packaged
implementation.  I don't know of one myself, and -- even if I did -- I wouldn't
trust it in a production environment.

   -- chris
Thomas Kellerer - 16 Feb 2006 14:56 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> output the method name, but I would like to log more than that. Any help is
> appreciated.

You could try to use Aspects (Aspect Oriented Programming - AOP) to
achieve this.

Have a look at the AspectJ manual, I think something like that is
actually described there.

http://www.eclipse.org/aspectj

Note, that although the URL points to eclipse it is not an Eclipse
exclusive technology. It can be used very well without Eclipse (it
offers a command line compiler and Ant tasks to integrate into your
build environment)

Regards
Thomas

Signature

It's not a RootKit - it's a Sony

Roedy Green - 17 Feb 2006 06:14 GMT
On Thu, 16 Feb 2006 15:56:31 +0100, Thomas Kellerer
<WVIJEVPANEHT@spammotel.com> wrote, quoted or indirectly quoted
someone who said :

>You could try to use Aspects (Aspect Oriented Programming - AOP) to
>achieve this.

would you care to share a paragraph singing the praises of Aspects?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Timo Stamm - 17 Feb 2006 06:57 GMT
Roedy Green schrieb:
> On Thu, 16 Feb 2006 15:56:31 +0100, Thomas Kellerer
> <WVIJEVPANEHT@spammotel.com> wrote, quoted or indirectly quoted
[quoted text clipped - 4 lines]
>
> would you care to share a paragraph singing the praises of Aspects?

http://c2.com/cgi/wiki?AspectOrientedProgramming

http://www.parc.com/research/projects/aspectj/default.html

Timo
Roedy Green - 17 Feb 2006 07:38 GMT
>http://c2.com/cgi/wiki?AspectOrientedProgramming
>
>http://www.parc.com/research/projects/aspectj/default.html

thanks. for future reference see
http://mindprod.com/jgloss/aspect.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

tom fredriksen - 16 Feb 2006 15:20 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> output the method name, but I would like to log more than that. Any help is
> appreciated.

You need to clear up one thing, aer you talking about automagically
printing all the information about a call, from say log4j. Or are just
talking about printing a log statement with a set of data arguments?

The last one is easy to perform, but it requires that you add a log
statement at the beginning, and possibly end, of each api method.

/tom


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



©2009 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.