• Home
  • Blog
  • Wiki
  • Projects
  • Contact Us






Use Logging Instead of println When Running Grails Integration Tests In IDEA.

January 4th, 2010 By admin

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.


Share:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • blogmarks
  • description
  • Furl
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • Netvouz
  • NewsVine
  • Ping.fm
  • Pownce
  • Reddit
  • StumbleUpon
  • Technorati
  • Tumblr
  • TwitThis
  • Yahoo! Buzz
  • YahooMyWeb

Posted in Grails | 1 Comment »




One Response to “Use Logging Instead of println When Running Grails Integration Tests In IDEA.”

  1. By Bob Herrmann
    on January 4th, 2010

    Or just,

    … logger = LoggerFactory.getLogger(${NAME}.class);


Leave a Reply

  • Categories

    • Build Automation
      • Maven
    • Development Environment Tricks
      • Cygwin
    • Dynamic Languages
      • Groovy
        • Grails
    • Java
    • JQuery
    • Test Automation
      • Selenium
    • Uncategorized

  • Archives

    • June 2010
    • March 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • September 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
  • Meta

    • Log in
    • RSS
    • Comments RSS
    • Valid XHTML
    • XFN
    • WP