Most Java developers know how annoying the process of fixing a bug can be. Usually it starts with trying to figure out where to actually start looking for the bug. In case of Java EE this by itself can be difficult, because layer after layer of indirection (caused by interceptors, proxies, filters, …) make stacktraces pretty difficult to read. Sometimes a stacktrace can contain dozens, even hundreds of methods. It’s like looking for a needle in a haystack. Finding that one line of our own code costs an experienced developer at least a few seconds, every time. An inexperienced developer is just totally overwhelmed and even scared to look at it!
Fortunately, Eclipse is very extensible and the community created plenty of plugins to help with nearly any problem. One plugin that will come in handy to help us, is “Grep Console” by Marian Schedenig. This little helper plugin is able to style the Eclipse console exactly how we would like it to look like.
“Grep Console” uses simple Regular Expressions, combined with Styles, to create a better console output. It ships a few default Expressions and Styles to highlight log messages of different levels (DEBUG, WARN, ERROR and FATAL). This might help a little bit, but we want only our own code to be highlighted in stacktraces. Thus, we are going to add a new Expression, with our own Style. How to do this is pretty straightforward. We would like every line which contains “at de.triona” (all our code is contained within these packages) to be highlighted. The Regular Expression to do so would be
.*(\Qat de.triona\E).* . In Eclipse, this will look like the following:
Now, we will try to force an exception and have a look at our new, beautified Eclipse console. Of course, the following exception was totally planned and did not happen on accident:
As you can see, it is impossible to miss the most important part of that stacktrace now and even a rookie developer will know where to start looking! Setting this up will take five minutes at most and will pay off very soon. The comprehensive user guide of the plugin can be found here.