some strange behavior : logger is not available in closure
What is going on here ?
Logger logger = Logger.getLogger("groovy.my.foo");
def printParameters() {
if(logger.isDebugEnabled())
logger.debug("print parameters")
binding.variables.each { key, value ->
logger.debug("Name=$key value= $value");
}
}
works only in case logger provided
def printParameters(Logger logger)
no problem with parameters ….
Thanks
A variable within a Groovy script is scoped. If you use a type or
defit is defined as local variable and is not accessible within a method. If you declare a variable without a type ordefit is added to the script’s binding and is usable in other methods.Here’s an example:
In your case defining the logger instance as
logger = Logger.getLogger("groovy.my.foo")should solve your problem.