Alex Rivera | Logout

How to log the time taken by methods in Springframework?

Asked 2009-09-30T05:08:41.303
9

Is it possible in springframework to log the time taken by methods [ selective | all ] automatically. By automatically i mean, i don't want to go to each method and write the log.debug ( "...." ); stuff.

Edit
Report

2 Answers

1

You can use AspectJ for this, declare a log pointcut called by wildcard with pre- and post handling by before() and after() advice.

answered 2009-09-30T05:31:02.037
1

I see that there has already been an accepted answer here, but I'd encourage everyone to take a look at the latest release of Spring Toolsuite (SpringSource's distro of Eclipse). It comes with a profiling utility out of the box, Spring Insight, that provides these exact statistics at runtime in a nice format. Just deploy your app to its internal tomcat, hit a few pages, then go to the /insight servlet and see the time taken in each method called all the way down to the SQL statements that were executed and how long they took.

Here's a link to a nice writeup about Spring Insight that should get you what you want in just a few minutes. http://www.dotkam.com/2009/10/28/spring-insight-in-action-5-minutes-from-scratch/

answered 2009-12-02T04:32:35.430

Your Answer