GrailsでHibernateのSQLログを出す

DataSource.groovyでloggingSqlをtrue、formatもしたい場合はformatSqlをtrueに。

dataSource {
    ...
    loggingSql = true
    formatSql = true
}

おなじDataSource.groovyで

hibernate {
    show_sql = true
    format_sql = true
    ...
}

としても同じ。

こんな感じで出る。

grails> Hibernate:
    select
        this_.id as id0_0_,
        this_.version as version0_0_,
        this_.bar as bar0_0_,
        this_.foo as foo0_0_,
        this_.hoge as hoge0_0_
    from
        hoge this_ limit ?
grails> Hibernate:
    select
        count(*) as y0_
    from
        hoge this_

ただこれだとcreate tableするあたりが出てくれない。その場合はorg.hibernateのログレベルdebugにすると以下の様な感じで出る。

2012-05-20 11:34:27,830 [pool-84-thread-1] DEBUG hbm2ddl.SchemaExport  -
    create table hoge (
        id bigint generated by default as identity,
        version bigint not null,
        bar varchar(255) not null,
        foo varchar(100) not null,
        hoge varchar(255) not null,
        primary key (id)
    )