Use Logging Instead of println When Running Grails Integration Tests In IDEA.
Here’s one for my fellow IDEA users. Have you ever noticed that when you run Grails integration tests within Intellij IDEA that all of the output from println’s ends up in a file called target/test-reports/plain/{name-of-test} ? This has always vexed me because I could never easily see what I was println’ing in Intellij’s Debug console window in ‘real time’ as I was debugging. I would have to wait until the end of my debugging session to go back and look at the output that had been captured to the file corresponding to my test in test/reports.
It was frustrating not to be able to see the output incrementally as each output statement was traversed in the debugger. Now I’ve found a simple way to accomplish this: I simply avoid using println completely and just rely on the logger instance that I’ve created for my class.
With Intellij you can easily set up a new Groovy (or Java, or whatever) file template and have a logger pre-set up for you before you start editing the new class. So there’s really no reason to keep using println.
Below is my template for new Groovy classes. This template automatically gives me a logger i can use instead of println
#if ( $PACKAGE_NAME != "" )package ${PACKAGE_NAME}
#end
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
#parse("File Header.java")
class ${NAME} {
private static Logger logger = LoggerFactory.getLogger("${PACKAGE_NAME}.${NAME}");
}
You can use this same template by selecting [F]ile / Se[t]tings from the main menu, then choosing ‘File Templates’, and picking Groovy.
























on January 4th, 2010
Or just,
… logger = LoggerFactory.getLogger(${NAME}.class);