grails (11) vaadin (11) meteor (6) java (4) elasticsearch (3) apple (2) centos (1) cloudbees (1) google analytics (1) gradle (1) heroku (1) javafx (1) javascript (1) jdbc (1) jug (1) logback (1) logging (1) mac os (1) management (1) mongodb (1) mongolab (1) mysql (1) twitter (1) ubuntu (1)

Thursday, August 15, 2013

Grails and Logback: Provide default logback configuration for development environment

The main motivation is to have a custom logger setup, which every developer can easily adjust. Also, we don't want to put logback config, which is meant for developers only, on the class path.

We can place logback.xml into the root folder of our project and then pass it when running up the application
grails -Dlogback.configurationFile=logback.xml run-app
The biggest disadvantage is: it is annoying to always include additional properties in the command line and it also means you need to tell that to the new developers. Also, it is not following Grails principle "convention over configuration".

We need to provide the default configuration for the development mode if logback.configurationFile property is not set.

So we hook after compilation event as follows. Create or open scripts/_Events.groovy file in your project folder.

Here is the content of _Events.groovy file.

In this example logback-config-dev.xml is ment to be stored in the project root folder.