log.debug { “$toStringMe only if necessary!” } March 19, 2010 | 01:02 pm

I’ve just updated the @WithLog AST transform for Groovy. In case you don’t know, that’s my project over at GitHub which allows you to turn:

import org.apache.log4j.Logger
 
class Foo { 
  static log = Logger.getLogger(Foo)
  /* ... */
}

into

@WithLog
class Foo {
  /* ... */
}

Three big changes in the new release. First, I switched to using Gradle for the build system, because Gradle is awesome. Second, I OSGi-ified the archive and released it to the Maven repo at http://repo.smokejumperit.com, so I’m now Java infrastructure compliant (thank you, Gradle, for making that a no-brainer). Third, I provided the ability to use an enhanced Logger implementation (unoriginally called WithLogLogger) — see the README for full details, but basically it means you can save the toString() evaluation on your logging messages if you wrap the logging GString in a Closure. If you use this, though, you’ll have to schlep around the Groovy-WithLog-0.2.jar file with your runtime code. If you’re using Maven/Ivy/Gradle/whatever, see the end of the README for repo information.

The @WithLog code is still released under the WTFPL.