I'm encountering this error:
groovy.lang.MissingPropertyException: No such property: log for class: org.utils.MyClass
Here's the content of the class:
package org.utils
class MyClass {
int organizationCount = 0
public int getOrganizationCount(){
log.debug "There are ${organizationCount} organization(s) found."
return organizationCount
}
}
Do i need to add an import statement? What do i need to add? Note that the class is located in src/groovy/org/utils. I know that the 'log' variable is accessible in controllers, services, etc. Not sure in 'src' classes.
Thanks.
Well I have done this in grails 3.1.8 which uses Logback.
In grails 3, the default logging system is logback. Simply adding the @Slf4j annotation to your src/groovy class will take care of things.
In Groovy 1.8, you may also annotate the class with
@Log
(for java.util.logging) or@Log4j
(for log4j) and it will "magically" have alog
property. See http://docs.codehaus.org/display/GROOVY/Groovy+1.8+release+notes#Groovy1.8releasenotes-@Log for details.PS.: If you use java.util.logging the
log.debug
call will still fail because there's nodebug
method.The log variable is injected by grails and thus only available in the grails-specific classes like controllers, services, etc. - and I don't think you can "import" that in any way.
Outside these classes, you'll just have to use log4j "regularly", i.e.
Log4j is one of the best logging for groovy
Log4j.properties
Hope it will help you....