如何写入Netbeans Debugger Console(在Java中)? [英] How do I write to the Netbeans Debugger Console (in Java)?
问题描述
Netbeans在Output部分中有一个标签窗口,名为Debugger Console。是否可以使用Java编写一个消息到这个窗口?如果是,那么如何?
您在调试器控制台中看到的消息是
$ ol
当您将断点添加到一行代码时,断点的默认行为是挂起执行代码行的线程,并打印文本线程{threadName}在类{className}中的{lineNumber}行的断点。
。
配置断点以打印自定义文本。当文本到达断点时,该文本将在调试器控制台中输出。为此,右键单击断点,打开propoerties窗口,并在字段打印文本
中输入您的文本。
一个有用的技巧是配置断点,使其不会阻塞( suspend:no thread
),并输入文本。效果与在代码中添加 println
行相同,但好处是您不必重新编译代码,并且更容易激活/停用这些调试器日志(它显然不会停留在生产代码上)。
请注意,在断点的文本中,可以使用特殊值 {lineNumber}
, {methodName}
, {className}
或 {threadName}
,您还可以使用语法 {= xxx}
来评估一些代码。只需用变量名称或方法调用替换xxx,或任何。
Netbeans has a tabbed window in the Output section called "Debugger Console". Is it possible to write a message to this window using Java? If so, how?
The messages you see in the debugger console are either
- informations given by the debugger itself (breakpoint added, for example)
- custom messages associated with a breakpoint
When you add a breakpoint to a line of code, the default behavior of the breakpoint is to suspend the thread that executed the line of code, and to print the text "Breakpoint hit at line {lineNumber} in class {className} by thread {threadName}."
.
You can configure a breakpoint to print a custom text. This text will be output in the debugger console when it reaches the breakpoint. To do so, right click on a breakpoint, open the propoerties window, and enter your text in the field Print text
.
A useful trick is to configure a breakpoint so that it does not block (suspend : no thread
), and to enter a text. The effect is the same than adding println
lines in your code, but the benefit is that you don't have to recompile the code, and it's easier to activate/deactivate these debugger logs (and it obviously does not stay on production code).
Note that, in the text of the breakpoint, you can use one of the special values {lineNumber}
, {methodName}
, {className}
or {threadName}
, and you can also evaluate some code with the syntax {=xxx}
. Just replace xxx with a variable name, or a method call, or whatever.
这篇关于如何写入Netbeans Debugger Console(在Java中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!