dataSource.logSql configurable from an external file so that after deployment I can decide if I want to see the SQL statements in logs or not.After a previous success with changing the
dataSource.url parameter in a properties file designated as an external configuration file I did exactly the same with the logSql option. It turned out not to work.However what did work was when I included not a ".properties" file but a ".groovy" file as the override configuration and then configured the
dataSource as follows:dataSource {
    logSql = false // disable SQL statements logging
}I've included the external configuration from the
environments block like this:// set per-environment serverURL stem for creating absolute links
environments {
    production {
        grails.config.locations = [ "file:/etc/example/example-config.groovy" ]
        grails.serverURL = "http://www.changeme.com"
    }
...That did the trick so I've tried to go one step further and completely reconfigure the
dataSource that previously used an embedded HSQL database to use MySQL:dataSource {
    logSql          = false
    driverClassName = 'com.mysql.jdbc.Driver'
    dialect         = 'org.hibernate.dialect.MySQL5InnoDBDialect'
    dbCreate        = 'update'
    url             = 'jdbc:mysql://127.0.0.1:3306/example'
    username        = 'root'
    password        = ....
}Obviously since there's no MySQL JDBC driver in my application I've had to supply one to the common libraries folder in Tomcat (in Ubuntu if you install Tomcat via apt-get then the folder is /var/lib/tomcat6/common, otherwise it's just the lib folder in your tomcat installation) and all worked just perfectly :)This is probably the best thing that ever happened to web application deployment :D This way you're able to completely reconfigure your application (even the most intimate things like bean properties if you so desire) and all that from as many configuration files as I want (just one works as well).
To utilize the new capabilities I've also reconfigured logging:
log4j = {
    appenders {
        file name: "application", file: "/var/example/log/example.log"
        file name: "stacktrace", file: "/var/example/log/stacktrace.log"
    }
    debug  application: 'grails.app'
    (the rest of usual logging settings here...)
}.That's soooo cool that I can do that :) It helps me be in line with what the admin of our production environment demands.
And best of all: NO DAMN XML WHATSOEVER :) I love being a Grails developer :)
No comments:
Post a Comment