grailsgrails-3.0grails-3.1

log is not accessible in normal groovy file of grails3


Migrated grails2 to grails3. In grails2 i used lots of
log.info,log.debug statements in side
src/main/groovy files. but in grails-3 by default
log is not injected.
it's giving error like No such property: log for class


Solution

  • This is a planned change. You can use @groovy.util.logging.Commons annotations on your non-grails classes to have log available. Also other like @Log4j, @Slf4j are available, depending on your logging library.

    There is one more difference which is important - those annotations will add log as private property and classes which will inherit from them, will also need to be annotated to use logging. Alternative is to manually define protected logger on your class.