RED-9349 - Add possibility to log stuff in the rules
This commit is contained in:
parent
b4b9213996
commit
d10e3f9b69
@ -17,6 +17,7 @@ import com.iqser.red.service.redaction.v1.server.logger.Context;
|
||||
|
||||
import com.iqser.red.service.redaction.v1.server.model.component.Component;
|
||||
import com.iqser.red.service.redaction.v1.server.model.component.Entity;
|
||||
import com.iqser.red.service.redaction.v1.server.service.components.ComponentMappingService;
|
||||
import com.iqser.red.service.redaction.v1.server.service.document.ComponentCreationService;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Change;
|
||||
@ -29,6 +30,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.FileAttribute;
|
||||
|
||||
global ComponentCreationService componentCreationService
|
||||
global ComponentMappingService componentMappingService
|
||||
global RulesLogger logger
|
||||
global Context context
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ class RulesLoggerTest {
|
||||
KieServices ks = KieServices.Factory.get();
|
||||
KieFileSystem kfs = ks.newKieFileSystem();
|
||||
|
||||
kfs.write(new ClassPathResource("drools/rules_logging.drl"));
|
||||
kfs.write(new ClassPathResource("logs/rules_logging.drl"));
|
||||
|
||||
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
|
||||
ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
|
||||
@ -79,7 +79,7 @@ class RulesLoggerTest {
|
||||
assertEquals(argument.getAllValues().get(1).getLogLevel(), LogLevel.WARN);
|
||||
assertEquals(argument.getAllValues().get(1).getMessage(), "This is a warning log with multiple placeholders p1 p2 p3");
|
||||
assertEquals(argument.getAllValues().get(2).getLogLevel(), LogLevel.ERROR);
|
||||
assertEquals(argument.getAllValues().get(2).getMessage(), "Exception during rule execution Exception: Exception executing consequence for rule \"LOG.0.1: Test log error\" in drools: java.lang.NullPointerException: Cannot invoke \"String.toString()\" because \"result\" is null");
|
||||
assertEquals(argument.getAllValues().get(2).getMessage(), "Exception during rule execution Exception: Exception executing consequence for rule \"LOG.0.2: Test log error\" in drools: java.lang.NullPointerException: Cannot invoke \"String.toString()\" because \"result\" is null");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
package drools
|
||||
|
||||
import com.iqser.red.service.redaction.v1.server.logger.RulesLogger;
|
||||
import com.iqser.red.service.redaction.v1.server.logger.Context;
|
||||
|
||||
global RulesLogger logger
|
||||
global Context context
|
||||
|
||||
|
||||
rule "LOG.0.0: Test log info"
|
||||
salience 1
|
||||
when
|
||||
eval(true)
|
||||
then
|
||||
logger.info(context, "This is a test log {}", "placeholder");
|
||||
end
|
||||
|
||||
rule "LOG.0.1: Test log warn"
|
||||
salience 1
|
||||
when
|
||||
eval(true)
|
||||
then
|
||||
logger.warn(context, "This is a warning log with multiple placeholders {} {} {}", "p1", "p2", "p3");
|
||||
end
|
||||
|
||||
rule "LOG.0.2: Test log error"
|
||||
when
|
||||
eval(true)
|
||||
then
|
||||
String result = null;
|
||||
result.toString();
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user