简体   繁体   中英

Java logging method calls?

Is there any tools that can be 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM