Cool Eclipse debugging tip

I found this great tip about adding logging to your code while it is running, without having to re-compile/re-deploy, using conditional breakpoints. Just add a breakpoint and insert your bit of logging code:

System.out.println(someValue);
return false;

Eclipse will execute the code and not pause because the condition returns false. In fact, you can add any code to the conditional, including changinge values, or logging to a file.

java.io.FileOutputStream out = new java.io.FileOutputStream("/temp/test.txt", true);
out.write(newValue.toString().getBytes());
out.write('\n');
out.close();
return false;

I’ve recently used this to debug a heavily-multi-threaded app that would get messed up if I tried to pause execution to inspect values.

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply