Grails hip tip: logging SQL
When working with Grails (especially, when slapping it over legacy database, man) it’s often helpful to see the hip SQL the framework generates when manipulating domain objects. As mapping a legacy database to Grails can be tricky (but indeed, solvable, baby!), seeing generated SQL can unveil incorrect mapping, etc.
Luckily, you can easily enable SQL logging without having to mess with Log4J configurations (i.e. debug, error, warn “packages blah blah”). In the DataSource.groovy file in your project’s grails-app/conf directory, simply add the loggingSql variable to a desired dataSource closure (that is, you can enable this feature for a particular environment or all of them) like so:
dataSource {
//blah blah
loggingSql = true
}
After that, you’ll notice that all SQL statements Grails (or really, Hibernate) utilizes will be logged to whichever appender you’ve configured (i.e. System.out, by default). This little tip has proved quite copacetic for me, man! Can you dig it?
| Related odds and ends | ||
|---|---|---|
1 comment Monday 08 Jun 2009 | Groovy
One Response to “Grails hip tip: logging SQL”
Also check out the P6Spy plugin – it will display SQL statements with the query parameters inline!
http://grails.org/p6spy+plugin