简体   繁体   English

Java记录方法调用?

[英]Java logging method calls?

Is there any tools that can be used to log all method calls from running java application? 有什么工具可用于记录正在运行的Java应用程序的所有方法调用?

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. 一些流行的探查器包括: JProfiler ,它具有在CPU和内存级别上执行方法调用记录的不同方法。

VisualVM is another one VisualVM是另一个

Many IDE's (I know Netbeans and Eclipse) have their own profilers you can use. 许多IDE(我知道Netbeans和Eclipse)都有自己可以使用的分析器。

One method would be to use AspectJ and write advice that intercepts method calls. 一种方法是使用AspectJ并编写可拦截方法调用的建议。 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 -aspects中的 @Loggable批注,它使用简单的日志记录机制包装了您要调试的所有方法:

@Loggable(Loggable.DEBUG)
public String load(URL url) {
  return url.openConnection().getContent();
}

It logs through SLF4J . 它通过SLF4J记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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