Drools Eclipse Plugin Audit View
原创
©著作权归作者所有:来自51CTO博客作者陈振阳Plus的原创作品,请联系作者获取转载授权,否则将追究法律责任
Rule Log Format
Audit View 不是运行时使用的,他是一个查看 Rule 执行日志的工具。
首先看一下 Rule 执行的日志的格式
<object-stream>
<org.drools.core.audit.WorkingMemoryLog>
<version>6.1</version>
<events>
<org.drools.core.audit.event.ObjectLogEvent>
<type>1</type>
<factId>1</factId>
<objectToString>com.secbro.drools.model.Customer@660f0c</objectToString>
</org.drools.core.audit.event.ObjectLogEvent>
<org.drools.core.audit.event.ObjectLogEvent>
<type>1</type>
<factId>2</factId>
<objectToString>com.secbro.drools.model.Customer@23b8d9f3</objectToString>
</org.drools.core.audit.event.ObjectLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>two same objects [2, 1]</activationId>
<rule>two same objects</rule>
<declarations>$secondCustomer=com.secbro.drools.model.Customer@660f0c; $firstCustomer=com.secbro.drools.model.Customer@23b8d9f3</declarations>
<factHandleIds>2,1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>two same objects [2, 1]</activationId>
<rule>two same objects</rule>
<declarations>$secondCustomer=com.secbro.drools.model.Customer@660f0c; $firstCustomer=com.secbro.drools.model.Customer@23b8d9f3</declarations>
<factHandleIds>2,1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>two same objects [2, 1]</activationId>
<rule>two same objects</rule>
<declarations>$secondCustomer=com.secbro.drools.model.Customer@660f0c; $firstCustomer=com.secbro.drools.model.Customer@23b8d9f3</declarations>
<factHandleIds>2,1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
</events>
</org.drools.core.audit.WorkingMemoryLog>
</object-stream>
可以看到,Rule 的执行日志并不是 Plain Text,而是有着特定格式的 XML 。也就意味着其是可以被很多的解析并展示的,Drools Eclipse Plugin Audit View 就是查看此文件的工具。
Aduit View
上边的日志文件打开之后会展示出上面的样子,文字前面的小图标对应不同的事件:
如何生成日志
KieServices kieServices = KieServices.get();
KieContainer kieContainer = kieServices.getKieClasspathContainer();
KieSession kieSession = kieContainer.newKieSession("all-rules");
KieRuntimeLogger logger = kieServices.getLoggers().newFileLogger( kieSession, "./helloworld" );
new一个KieRuntimeLogger 之后,就会自动生成日志。