Jakob Külzer Ninja Coding Monkey goes Canada

14Aug/081

Grails and Logging: “No such property”

Today I am working on my software project again (after a big pile of paperwork - yuck!). Grails uses log4j as logging system which is IMHO quite a good choice. Configuration is done via the Config.groovy located in the grails-app/conf directory of a Grails application. There you add entries to the log4j block which sounds pretty easy at first, but there is a pitfall with this block. When you add entries in the wrong order, you'll get a disturbing error when starting your application, something like this:

Failed to compile configuration file .../proj/grails-app/conf/Config.groovy: \
    No such property: app.service for class: java.lang.String

This is an error I had for couple of times and on the grails user mailing list this question has been asked for a few times, too. The problem seems to be the order of the entries. Take for example the following block that should set the loglevel for all services to debug while keeping the rest of the application at the error-level:

log4j {
  logger {
    grails="error"
    grails.app.service="debug"
  }
}

It will fail. However, if you swap the lines, it will work:

log4j {
  logger {
    grails.app.service="debug"
    grails="error"
  }
}

I'm still trying to figure out why it is the way it is, but this is a quick and easy workaround that seems to work - I've tested it with three different samples and it did the trick. As a rule of thumb, sort your logger configuration by length in a descending order.

Hopefully I could save you a few more minutes. :-)

Filed under: Grails Leave a comment
Comments (1) Trackbacks (0)
  1. I’m in no way a Grails expert, but just looking at your example I can’t help assuming…

    1. grails=”error” effectively changes the type of grails to String
    2. Then, any reference to grails will treat grails as String, causing grails.app.service=”debug’ to be equivalent to “debug”.app.service=”debug”: No such property: app.service for class: java.lang.String

    The way these settings are being interpreted appears to be somewhat cumbersome :-(


Leave a comment


No trackbacks yet.