Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log SQL statements in Grails

I want to log in the console or in a file, all the queries that Grails does, to check performance.

I had configured this without success.

Any idea would help.

like image 816
user2427 Avatar asked Apr 02 '10 18:04

user2427


2 Answers

Setting

datasource {
...
logSql = true
}

in DataSource.groovy (as per these instructions) was enough to get it working in my environment. It seems that parts of the FAQ are out of date (e.g. the many-to-many columns backwards question) so this might also be something that changed in the meantime.

like image 127
Tomislav Nakic-Alfirevic Avatar answered Oct 13 '22 04:10

Tomislav Nakic-Alfirevic


I find it more useful to do the following, which is 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).

In your Config.groovy, add the following to your log4j block:

log4j = {

    // Enable Hibernate SQL logging with param values
    trace 'org.hibernate.type'
    debug 'org.hibernate.SQL'
    //the rest of your logging config
    // ...
    }
like image 42
Peter Avatar answered Oct 13 '22 06:10

Peter