The built-in audit trail records what happened during rule processing at the business level.
Use the audit trail when you need to inspect:
This is different from diagnostic logging. The audit trail is about rule outcomes. Logging is about operational and debugging messages.
After processing a context, the main inspection methods are:
ctx.getLog() for the ordered list of invoked rules and their effectsctx.getExceptions() for exceptions raised during evaluationctx.getOutput() for the final output after rule executionEach entry returned by ctx.getLog() contains:
rule, the rule instance that raneffect, a RuleEffect value that may include properties such as satisfied, changed, or exceptionimport { Workspace } from '@samatawy/rules';
const workspace = new Workspace({
strict_inputs: false,
strict_outputs: false,
});
workspace.typeRegistry().addRootType({
key: 'Person',
properties: {
age: 'number',
is_adult: 'boolean',
},
});
workspace.addRule('@name(Adult Check) IF Person.age >= 18 THEN Person.is_adult = true');
workspace.addRule('@name(Reject Negative Age) IF Person.age < 0 THROW "Invalid age"');
const ctx = workspace.loadContext({
Person: {
age: 22,
is_adult: false,
},
});
workspace.process(ctx);
const auditTrail = ctx.getLog().map((entry) => ({
rule: entry.rule.toString(),
effect: entry.effect,
}));
console.log(auditTrail);
console.log(ctx.getExceptions());
console.log(ctx.getOutput());
The audit trail is the right feature for:
If you need structured operational logs, log levels, or external sinks, use the logger system instead.