1

Is it possible to create some sort of "trace breakpoint" in eclipse whereby Eclipse will log variables that I choose to a file when a "breakpoint" is hit without pausing the application?

Benjamin Confino
  • 2,344
  • 3
  • 26
  • 30

2 Answers2

3

Sure. For this sample method:

public static void logArgs(final String one, final String two) {
    System.out.println(one + two);
}

put your breakpoint in it, right click it and edit Breakpoint properties... as in the example. The important checkboxes are Conditional and Suspend when 'true'. Just return false so that breakpoint does not suspend at all.

java.io.FileWriter w = new java.io.FileWriter("/tmp/file.txt", true);
w.write(String.format("args(%s, %s)%n"), one, two));
w.close();
return false;

enter image description here

Benjamin Confino
  • 2,344
  • 3
  • 26
  • 30
Michał Grzejszczak
  • 2,599
  • 1
  • 23
  • 28
  • 1
    Great answer. And if you write all four statements on one line, it also works in the expression view. – weberjn May 25 '22 at 15:06
1

For Java 11 Michał Grzejszczak's answer can be written as java.nio.file.Files.writeString(java.nio.file.Path.of("f.txt"), "My string to save");return true;

(Best way to write String to file using java nio)

weberjn
  • 1,840
  • 20
  • 24