Will the Slf4j annotation work in Grails?

I have a Groovy library that registers with an annotation @Slf4j

provided by Groovy:

@Slf4j
class SomePogo {
    // do stuff
}

      

If I drop this library into a Grails application (2.4.2), will the log4j logging system by default collect log records in these classes? Or do I need to add log4j loggers to all my classes?

+3


source to share


1 answer


All Grails artifacts (controllers, domain classes, tags, services, etc.) automatically add a static registrar field (named log

) to them.



The classes src/groovy

also automatically add a named log field log

, but in this case the log is nonstationary. Therefore, the only time you need to explicitly add the log is if you want to statically log something from the class src/groovy

. In such a case, you will need to annotate the class @Slf4j

(or @Log4j

) to replace the non-static logger added by Grails with a static field log

.

+6


source







All Articles