Grails SQL Logging

SQL logging is important not only for debugging problems but for keeping an eye on the database usage of your application.  No matter how efficient we try to be frameworks that isolate us from the database often result in problems like N+1 queries which can be catastrophic on large production data sets.

To enable SQL Logging in Grails v1.1.1, just add a single line to your data source configuration in /grails-app/conf/DataSource.groovy.

loggingSql=true

For example, if our development data source looks like this:

environments {
    development {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgresql:foobar"
        }
    }
}

This will be our version with SQL Logging enabled:

environments {
    development {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgresql:foobar"
            loggingSql=true
        }
    }
}
0 Votes