views:

24

answers:

2

I try log some details in a namedQuery for a grails domain class but logging errors.

static namedQueries = {
  firstThree {
    if (booleanValue) {
       log.trace "booleanValue = true"
       eq ('bar', foo)
    }
    maxResults(3)
  }
}

Error

No such property: log for class: grails.orm.HibernateCriteriaBuilder

How do I log in a criteria?

A: 
System.out.println "booleanValue = true"

does solve it!

skurt
It might solve it, but where does the output go, when you go into production.
sbglasius
point taken, but it was only for development
skurt
+1  A: 

The problem is that the log property isn't static so it's not visible from the static closure. You could create your own static logger and use that, e.g.

static final Logger LOG = Logger.getLogger('some.logging.category.name')

and then use that:

static namedQueries = {
  firstThree {
    if (booleanValue) {
       LOG.trace "booleanValue = true"
       eq ('bar', foo)
    }
    maxResults(3)
  }
}
Burt Beckwith