You can use a KnowledgeBuilder with template-derived DRL-resources and set up your KnowledgeBase from its results the same way you do it with plain .drl-files. Obtain a StatefulKnaowledgeSession and pass this to the KnowledgeRuntimeLoggerFactory, as in your first code sample.
-W

 
On 6/30/09, chris@twc <christopher.mcfarland@twc.state.tx.us> wrote:
I'm trying to figure out how I can create a Logger to log rule activations for my Template File code. I followed the examples to successfully create a Logger for DRL and Decision Table examples. Apparently, to create a Logger, the KnowledgeRuntimeLoggerFactory methods take a KnowledgeRuntimeEventManager type, which StatefulKnowledgeSession implements. But, for the Template File examples, the StatefulSession from the "unstable" drools-core *does not* implement this interface. SEE the code examples below - how do I create a Logger for my Template File code?

//#### DRL FILE & EXCEL FILE EXAMPLE FOR CREATING A SESSION AND FIRING THE RULES:
//#### CREATING A RULES LOGGER WORKS

// populate working memory
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(...[DRL or DTABLE resources]...);
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
// create session
StatefulKnowledgeSession rulesSession = knowledgeBase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger rulesLogger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(rulesSession); //<<CREATE LOGGER!
FactHandle factHandle = rulesSession.insert(myFact);
// fire the rules
rulesSession.fireAllRules();
//#### TEMPLATE FILE EXAMPLE FOR CREATING A SESSION AND FIRING THE RULES:
//#### CREATING A RULES LOGGER DOES NOT COMPILE!

// populate working memory
ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler();
InputStream spreadsheetStream = ...
InputStream templateFileStream = ...
String drl = converter.compile(spreadsheetStream, templateFileStream, 3, 3);
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new StringReader(drl));
RuleBase templateRuleBase = RuleBaseFactory.newRuleBase();
templateRuleBase.addPackage(builder.getPackage());
// create session
StatefulSession rulesSession = templateRuleBase.newStatefulSession();
KnowledgeRuntimeLogger rulesLogger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(rulesSession);//<<DOESN'T COMPILE!
FactHandle factHandle = rulesSession.insert(myFact);
// fire the rules
rulesSession.fireAllRules();


View this message in context: Drools 5 - how create Logger for Template File based rules?
Sent from the drools - user mailing list archive at Nabble.com.


_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users