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.
In grails 3, the default logging system is logback. Simply adding the @Slf4j annotation to your src/groovy class will take care of things.
import groovy.util.logging.Slf4j
@Slf4j
class MyUtil {
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 a log
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 no debug
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With