Groovy Dependency Injection

I want to add Log4j Logger (or in the case of generality of any class) to all my classes that have the log property:

def log

This is done automatically in Grails. I want to have the same function in regular groovy applications, say for all groovy files in a section src. The specialty of Log4j is that the registrar needs to know the class that should be registered. ( Logger.getLogger(Class clazz))

How can i achieve this?

+5
source share
2 answers

Have you seen the added annotation @Login Groovy 1.8?

+11
source

Groovy , @Log4j . log, Log4J Logger , , , :

package com.example
import groovy.util.logging.Log4j

@Log4j
public class LogExample {
}

package com.example
public class LogExample {
  private static final Logger log = Logger.getLogger(LogExample.class)
}
+3

All Articles