Search code examples
grailsgrails3

Grails 3 logging in src folder not injecting log object


In the src folder of the grails 3 app:

enter image description here

I have a lot of log.xyz and they are is throwing the following exception:

Caused by: groovy.lang.MissingPropertyException: No such property: log for class: com.myApp.runner.RunnerThreadPoolExecutor

Which seems odd as this is a migrated app from grails 2 and having the log object in those classes was very useful.

I can add the following to each class:

import org.slf4j.Logger
import org.slf4j.LoggerFactory

static Logger log = LoggerFactory.getLogger(SomeClass.class)

But this seems very long winded and a bit a backwards step. Am I missing something in the configuration somewhere?


Solution

  • Just add the slf4j annotation to your classes:

    package com.example
    
    import groovy.util.logging.Slf4j
    
    @Slf4j
    class MySample {
       def test() {
          log.debug("log this!")
       } 
    }