Monday, July 2, 2012

Logging with groovy in BC4J components

We can use  Groovy  expressions to simplify java object access or method execution. In this article, We need to use Logging inside Groovy  scripts.This can be achieved by  using the ADF Logger. Just add script similar to this into your Groovy code  (e.g inside custom entity validators)

//Create a logger instance for  the entity class "Employees in this example"
oracle.adf.share.logging.ADFLogger LOGGER =
          oracle.adf.share.logging.ADFLogger.createADFLogger(source.getClass())

LOGGER.info("Groovy Log exemple: oldValue= "+oldValue)
LOGGER.info("Groovy Log exemple: newValue= "+newValue)
LOGGER.info("Groovy Log exemple: Sum of all salaries in a Department
            "+Departments1.Employees1.sum('Salary'))
LOGGER.info("Groovy Log exemple: departement remaining budget "+(100000 -
        (Departments1.Employees1.sum('Salary')+ newValue) + oldValue ))
Like In Java, you define a variable to hold the logger reference then use it to print info messages