Class Logger

java.lang.Object
com.avoka.tm.util.Logger
All Implemented Interfaces:
com.avoka.core.groovy.runtime.IBindable

public class Logger extends Object implements com.avoka.core.groovy.runtime.IBindable

Provides a Logger class for logging information during the execution of Groovy scripts. A logger instance will be injected into groovy script object before it is invoked. To use the Logger a groovy script class must provide a public Logger field with the name logger.

Service Example

The Groovy class below example below declares a public Logger variable with is used for logging.

 import com.avoka.tm.util.*
 import com.avoka.tm.vo.*
 import jakarta.servlet.http.*

 class FluentGroovyService {

     // Injected at runtime
     public Logger logger

     Object invoke(SvcDef svcDef, HttpServletRequest request, User user, Map params) {

         logger.info 'groovy result - ' + params.formId

         return null
     }
 } 

Unit Test Example

When using a Logger in a JUnitTest you must specify that the logger field is static otherwise a NPE will occur. This is because the JUnitTest runner will clone the unit test object when executing separate unit test methods to ensure their state is well isolated from other unit test methods.

 import com.avoka.tm.svc.*
 import com.avoka.tm.test.*
 import com.avoka.tm.util.*
 import com.avoka.tm.vo.*
 import org.junit.*

 class UnitTest extends AbstractJUnitTest {

     // Injected at runtime
     public static Logger logger

     // Perform service unit test
     @Test
     void test() throws Exception {

         Map args = [
             "formId": 23
         ]

         Map params = [
             "svcDef": svcDef,
             "request": null,
             "user": null,
             "params": args
         ]

         def result = new ServiceInvoker(svcDef).invoke(params)

         // Check result
         logger.info params

         assert "groovy result - 23" == result
     }
 } 
Since:
17.10.0
  • Constructor Details

    • Logger

      public Logger()
      Create a logger instance.
    • Logger

      public Logger(boolean standalone)
      Create a logger instance.
      Parameters:
      standalone - log message to console.
  • Method Details

    • debug

      public void debug(Object object)
      Log the given DEBUG level message.
      Parameters:
      object - the DEBUG level message
    • debug

      public void debug(String object)
      Log the given DEBUG level message.
      Parameters:
      object - the DEBUG level message
    • error

      public void error(Object object)
      Log the given ERROR level message.
      Parameters:
      object - the ERROR level message
    • error

      public void error(String object)
      Log the given ERROR level message.
      Parameters:
      object - the ERROR level message
    • info

      public void info(Object object)
      Log the given INFO level message.
      Parameters:
      object - the INFO level message
    • info

      public void info(String object)
      Log the given INFO level message.
      Parameters:
      object - the INFO level message
    • warn

      public void warn(Object object)
      Log the given WARN level message.
      Parameters:
      object - the WARN level message
    • warn

      public void warn(String object)
      Log the given WARN level message.
      Parameters:
      object - the WARN level message
    • getBindingName

      public String getBindingName()
      Specified by:
      getBindingName in interface com.avoka.core.groovy.runtime.IBindable
      Returns:
      the binding name "logger".
      See Also:
      • IBindable.getBindingName()
    • getBindingType

      public ElementType getBindingType()
      Specified by:
      getBindingType in interface com.avoka.core.groovy.runtime.IBindable
      Returns:
      the binding type ElementType.FIELD
      See Also:
      • IBindable.getBindingType()
    • getDebugLevelLogBuilder

      public StringBuilder getDebugLevelLogBuilder()
      Returns:
      the logger instance debug level log builder, or null if not used
    • getInfoLevelLogBuilder

      public StringBuilder getInfoLevelLogBuilder()
      Returns:
      the logger instance info level log builder, or null if not used