- All Implemented Interfaces:
com.avoka.core.groovy.runtime.IBindable
public class Logger
extends java.lang.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 javax.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
Constructors
Constructor |
Description |
Logger() |
Create a logger instance.
|
Logger(boolean standalone) |
Create a logger instance.
|
Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type |
Method |
Description |
void |
debug(java.lang.Object object) |
Log the given DEBUG level message.
|
void |
debug(java.lang.String object) |
Log the given DEBUG level message.
|
void |
error(java.lang.Object object) |
Log the given ERROR level message.
|
void |
error(java.lang.String object) |
Log the given ERROR level message.
|
java.lang.String |
getBindingName() |
|
java.lang.annotation.ElementType |
getBindingType() |
|
java.lang.StringBuilder |
getDebugLevelLogBuilder() |
|
java.lang.StringBuilder |
getInfoLevelLogBuilder() |
|
void |
info(java.lang.Object object) |
Log the given INFO level message.
|
void |
info(java.lang.String object) |
Log the given INFO level message.
|
void |
warn(java.lang.Object object) |
Log the given WARN level message.
|
void |
warn(java.lang.String object) |
Log the given WARN level message.
|
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,
wait, wait, wait
Constructor Detail
Logger
public Logger()
Create a logger instance.
Logger
public Logger(boolean standalone)
Create a logger instance.
- Parameters:
standalone
- log message to console.
Method Detail
debug
public void debug(java.lang.Object object)
Log the given DEBUG level message.
- Parameters:
object
- the DEBUG level message
debug
public void debug(java.lang.String object)
Log the given DEBUG level message.
- Parameters:
object
- the DEBUG level message
error
public void error(java.lang.Object object)
Log the given ERROR level message.
- Parameters:
object
- the ERROR level message
error
public void error(java.lang.String object)
Log the given ERROR level message.
- Parameters:
object
- the ERROR level message
info
public void info(java.lang.Object object)
Log the given INFO level message.
- Parameters:
object
- the INFO level message
info
public void info(java.lang.String object)
Log the given INFO level message.
- Parameters:
object
- the INFO level message
warn
public void warn(java.lang.Object object)
Log the given WARN level message.
- Parameters:
object
- the WARN level message
warn
public void warn(java.lang.String object)
Log the given WARN level message.
- Parameters:
object
- the WARN level message
getBindingName
public java.lang.String getBindingName()
- Specified by:
-
getBindingName
in interface
com.avoka.core.groovy.runtime.IBindable
- Returns:
- the binding name "logger".
- See Also:
IBindable.getBindingName()
getBindingType
public java.lang.annotation.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 java.lang.StringBuilder getDebugLevelLogBuilder()
- Returns:
- the logger instance debug level log builder, or null if not used
getInfoLevelLogBuilder
public java.lang.StringBuilder getInfoLevelLogBuilder()
- Returns:
- the logger instance info level log builder, or null if not used