Magic in IntelliJ IDEA - Invisible trace output
Join the DZone community and get the full member experience.
Join For FreeIf you at least occasionally add tracing output messages to your code to narrow down a problem, you might find this tip useful.
I'll show you how to avoid polluting you code with all the System.out.println() statements and yet be able to see in the output, whether your program has reached the parts of your code you're interested in. No need to remember all the places where you've added tracing messages to be able to remove them once you're done fixing. No need to comment and uncomment the lines with the tracing messages you're interested in just now.
System.out.println("Hurray, we've just got here.");
System.out.println("Time to call foo().");
Foo foo = foo();
System.out.println("Got back from foo(). Received " + foo);
System.out.println("Time to finish.");
On top of that you get handy capability to turn all or some of the tracing messages on and off using a dedicated, smooth UI. Any ideas about what I'm talking about here?
Breakpoints that print trace messages and don't stop your program
You probably got the idea by now. Instead of adding a System.out.println() statement to your code, just set a breakpoint.
Open-up the properties for the breakpoint, mark it with None for Suspend policy and check the Log message to console checkbox.
Additionally you may consider customizing the output message in the Log evaluated expression box. The code you type into the field is of course validated and auto-completed.
From now on, whenever the breakpoint is hit during a debugging session, a message is printed to the console.
Just like usual breakpoints the tracing breakpoints can be selectively enabled/disabled and your tracing messages don't mess-up with the usual program output once run outside of the debugger.
Opinions expressed by DZone contributors are their own.
Trending
-
Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
-
How To Use Pandas and Matplotlib To Perform EDA In Python
-
Operator Overloading in Java
-
Exploratory Testing Tutorial: A Comprehensive Guide With Examples and Best Practices
Comments