Tuesday, November 6, 2012

Debugging with sysouts made awesome

At times I like to debug by writing to console. However, in a long debugging session I often end up with several sysout statements in several files/methods, which makes it hard to track where a particular line of console output came from.

In the past I tried to use code templates to also print the 'enclosing type' and 'enclosing method', but I often forgot to use the template. In any case, via templates you cannot 'link' back to the source code.

Jeeeyul presents a neat solution - just replace PrintStream by a DebugStream so that you can also print 'file : line number : method name' information. I took this code, added it to a plugin and then added this plugin to my launch config. Now everytime I launch an Eclipse Application 'DebugStream' gets activated. 

Essentially, the plugin converts console messages from
Hello World.
to include a link to the source code
(HelloWorld.java:10) main(..) : Hello World.

No comments:

Post a Comment