|
Is there a way to log what rules have interacted with a fact -- and keep the logging with the fact? What are the best practices for that?
For example, facts are unmarshalled from an XML stream: <important_fact> <foo>bar</foo> </important_fact> Then my rules interact with it: rule "my rule" no-loop true dialect "mvel" when i : important_fact() then i.setFoo("fee"); end rule "my second rule" no-loop true dialect "mvel" when i : important_fact( foo = "fee" ) then i.setFoo(i.getFoo + "foo"); end Then I'm thinking I'd like the marshalled output to be something like this (except maybe with unique rule IDs instead of just names): <important_fact> <foo>feefoo</foo> <rule_history> <rule>my rule</rule> <rule>my second rule</rule> </rule_history> </important_fact> But I'm pretty new at this. Is that ever done? If so, what are the best practices? If not, maybe there's a good reason, so why not? |
|
Create an AgendaEventListener and let it listen to
BeforeActivationFiredEvent. The passed ActivationEvent contains a reference to an Activation object, from which you getObjects all participating fact objects. Now it depends whether your "important facts" all implement the interface RuleHistory or not. If they do, you just add the rule's name which is available via the Rule object also referenced by the Activation. Otherwise you'll have to design a way of referring to your objects and bundle a reference to the fact with the rule name, to create a list of pairs: reference and rule name. -W On 08/08/2012, BenjaminWolfe <[hidden email]> wrote: > Is there a way to log what rules have interacted with a fact -- and keep > the > logging with the fact? What are the best practices for that? > > For example, facts are unmarshalled from an XML stream: > > <important_fact> > <foo>bar</foo> > </important_fact> > > Then my rules interact with it: > > rule "my rule" > no-loop true > dialect "mvel" > when > i : important_fact() > then > i.setFoo("fee"); > end > > rule "my second rule" > no-loop true > dialect "mvel" > when > i : important_fact( foo = "fee" ) > then > i.setFoo(i.getFoo + "foo"); > end > > Then I'm thinking I'd like the marshalled output to be something like this > (except maybe with unique rule IDs instead of just names): > > <important_fact> > <foo>feefoo</foo> > <rule_history> > <rule>my rule</rule> > <rule>my second rule</rule> > </rule_history> > </important_fact> > > But I'm pretty new at this. Is that ever done? If so, what are the best > practices? If not, maybe there's a good reason, so why not? > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Logging-Rules-Fired-on-a-Fact-Best-Practices-tp4019054.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > _______________________________________________ > rules-users mailing list > [hidden email] > https://lists.jboss.org/mailman/listinfo/rules-users > rules-users mailing list [hidden email] https://lists.jboss.org/mailman/listinfo/rules-users |
| Powered by Nabble | Edit this page |
