[rules-users] Drools 5 - how create Logger for Template File based rules?

Wolfgang Laun wolfgang.laun at gmail.com
Wed Jul 1 02:51:13 EDT 2009


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 at twc <christopher.mcfarland at 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?<http://www.nabble.com/Drools-5---how-create-Logger-for-Template-File-based-rules--tp24277191p24277191.html>
> Sent from the drools - user mailing list archive<http://www.nabble.com/drools---user-f11823.html>at Nabble.com.
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090701/0fa486d4/attachment.html 


More information about the rules-users mailing list