5

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?

JoeyHolloway
  • 458
  • 7
  • 19
  • Grails 3 uses logback by default, do you have a `/grails-app/conf/logback.groovy` file? http://docs.grails.org/latest/guide/single.html#logging – Mike W Jan 16 '18 at 13:00
  • I do - thanks for the link, it seems to confirm @SaschaFrinken answer below – JoeyHolloway Jan 17 '18 at 10:09

1 Answers1

8

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!")
   } 
}
Sascha Frinken
  • 3,134
  • 1
  • 24
  • 27
  • This makes it a lot easier but I have about 150 classes. I was wondering if there is a way/ setting to have it working like grails 2 with the log object automatically in those classes. – JoeyHolloway Jan 17 '18 at 10:07