Print more logging messages during debugging

Sometimes, in debug mode,  more logging messages could be very helpful. We can change code to add more logs. But it’s not efficient as the code need to be re-compiled and later some log message may need to be removed after debugging.

Java debugger provides very powerful way to achieve this, which allows to print more messages and even more.

Take Eclipse for example, here I have a simple HelloWorld to calculate the sum from 0 to 99. In debugging, I want to see how sum changed in the loop but I don’t want to stop application and click “Continue” every time.

12-12-2014 5-31-25 PM

So first, I added a break point on line 8. Next, I edited the “Breakpoint Properties”. In the conditional text input, you can print some message first and make the return of expression as false.

12-12-2014 5-35-40 PM

To return false will make debugger not stop at line 8, but just print the log messages I want.

12-12-2014 5-37-57 PM

You can see it’s totally non-intrusive. Actually, you can put more complicated statements there and also you can control when to return true or false. It’s very flexible. In other IDEs, such as JetBrains IDEA and Netbeans, there are similar functions.