Package com.avoka.tm.util
Class Logger
java.lang.Object
com.avoka.tm.util.Logger
- All Implemented Interfaces:
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Log the given DEBUG level message.void
Log the given DEBUG level message.void
Log the given ERROR level message.void
Log the given ERROR level message.void
Log the given INFO level message.void
Log the given INFO level message.void
Log the given WARN level message.void
Log the given WARN level message.
-
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
Log the given DEBUG level message.- Parameters:
object
- the DEBUG level message
-
debug
Log the given DEBUG level message.- Parameters:
object
- the DEBUG level message
-
error
Log the given ERROR level message.- Parameters:
object
- the ERROR level message
-
error
Log the given ERROR level message.- Parameters:
object
- the ERROR level message
-
info
Log the given INFO level message.- Parameters:
object
- the INFO level message
-
info
Log the given INFO level message.- Parameters:
object
- the INFO level message
-
warn
Log the given WARN level message.- Parameters:
object
- the WARN level message
-
warn
Log the given WARN level message.- Parameters:
object
- the WARN level message
-
getBindingName
- Specified by:
getBindingName
in interfacecom.avoka.core.groovy.runtime.IBindable
- Returns:
- the binding name "logger".
- See Also:
-
IBindable.getBindingName()
-
getBindingType
- Specified by:
getBindingType
in interfacecom.avoka.core.groovy.runtime.IBindable
- Returns:
- the binding type ElementType.FIELD
- See Also:
-
IBindable.getBindingType()
-
getDebugLevelLogBuilder
- Returns:
- the logger instance debug level log builder, or null if not used
-
getInfoLevelLogBuilder
- Returns:
- the logger instance info level log builder, or null if not used
-