Log and Debug GORM

Sometimes its necessary to see the sql queries executed by GORM, so its possible to troubleshoot an issue. In this post, we cover different ways doing just that

1. One way is to enable SQL logging by adding following line in conf/DataSource.groovy:

   development {
        dataSource {
            dbCreate = "" // one of 'create', 'create-drop', 'update', 'validate', ''
            logSql = true

This enables SQL logging to stdout

2. Second way, is to to enable Hibernate’s logging to log the SQL along with bind variables (so you can see the values passed into your calls, and easily replicate the SQL in your editor or otherwise). Add the following lines conf/Config.groovy:

// log4j configuration
log4j = {
    // Enable Hibernate SQL logging with param values
    trace 'org.hibernate.type'
    debug 'org.hibernate.SQL'

3. Third way, is to profile GORM with some utility such as P6Spy
…coming in future

Leave a Reply

Your email address will not be published. Required fields are marked *