Tracepoints in Eclipse
debugging, eclipse, java, trace
Solution
Eclipse supports conditional breakpoints.
All you have to do, is provide it with a boolean expression, and it'll be happy. In this case, a static method that also prints useful stuff as a side effect is fine.
public class TracePointUtils {
static private Logger logger = org.slf4j.LoggerFactory.getLogger(TracePointUtils.class);
/** Produce a WARN message in SL4J logger */
public static boolean trace(String msg, Object ... args) {
logger.warn(format(msg, args));
// Do not stop
return false;
}
}
Here, I use SL4J as a logger, but a plain println would be fine.
Then, add a breakpoint in your code, and call this static method as the condition:
Et voila, you can enjoy nice traces in your console.
Problem
There seem to be no support for tracepoints in Eclipse (JDT) debug mode. This is really a bummer, since you may sometime want to print a lot of debug infomation without cluttering your code with hardcoded println that you are likely to forget later on. I found a simple workaround for that and wanted to share with SO.