Java logging method calls?
Is there any tools that can be开发者_如何学Go used to log all method calls from running java application?
eg.
String str = "...";
String anotherString = str.trim();
should log something like this:
..method call trim() from class java.lang.String
What you need is a profiler.
Some popular profilers are: JProfiler which has different ways to do method call recording, both on CPU and memory level.
VisualVM is another one
Many IDE's (I know Netbeans and Eclipse) have their own profilers you can use.
One method would be to use AspectJ and write advice that intercepts method calls. There is an example of how to do this "tracing" logging in the programmer guide.
You can use @Loggable
annotation from jcabi-aspects, which wraps all methods you want to debug with a simple logging mechanism:
@Loggable(Loggable.DEBUG)
public String load(URL url) {
return url.openConnection().getContent();
}
It logs through SLF4J.
精彩评论