Java Developer

Adding SQL logging to your Grails application

While ORM is great in simplifying our work with the database, it is still very useful to know SQL statements our application is throwing at the database. Specially when we are still developing the application.

Enabling this in Grails is very simple. Open up DataSource.groovy and add the line loggingSql. For example:

dataSource {
...
}
hibernate {
...
}
environments {
    development {
        dataSource {
            username = "root"
            password = "root"
            dbCreate = "update"
            loggingSql  = true
            url = "jdbc:mysql://localhost:3306/awesome_db"
        }
    }
   ...
}

Although this is too simple, I can't resist sharing it and documenting it for my future use.
Tags: datasource, gorm, grails, log, logging, orm