简体   繁体   English

如何在 Eclipse 中调试时将 Java 对象的当前值打印到控制台,而不是挂起线程?

[英]How to print Java object's current value to console, instead of suspend thread while debug in the Eclipse?

Sometimes you need just to check how are some values in your application changing in time.有时您只需要检查应用程序中的某些值是如何随时间变化的。 Usually, you can use the log, but imagine that your application is on severs already and make the whole CI/CD cycle, just to add a few temporary log statements is overkill.通常,您可以使用日志,但假设您的应用程序已经在服务器上并进行整个 CI/CD 循环,仅添加一些临时日志语句就大材小用了。 Or variables are in 3-rd party libraries, and you don't want to patch it.或者变量在 3-rd 方库中,您不想修补它。

Of course, you can (remotely) debug your application, but it may be an issue to suspend the thread and check several variables again and again and again.当然,您可以(远程)调试您的应用程序,但暂停线程并一次又一次地检查多个变量可能是个问题。

Such functionality is available in the JetBrains IntelliJ IDEA out of the box - tracepoint, but what about Eclipse? JetBrains IntelliJ IDEA 开箱即用 - tracepoint 中提供了此类功能,但是 Eclipse 呢?

Fortunately, you can implement the "virtual logging" with Eclipse.幸运的是,您可以使用 Eclipse 实现“虚拟日志记录”。

To do it:去做吧:

  1. Start the debug session开始调试 session
  2. add the conditional breakpoint to the line that you want to add a log statement将条件断点添加到要添加日志语句的行
  3. Write the log statement to the breakpoint condition and return false;将日志语句写入断点条件, return false;

在此处输入图像描述

That's all.就这样。 The application will not suspend while passing breakpoint but will write to output the value of the variable应用程序在通过断点时不会挂起,而是将变量的值写入 output

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

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