Using a Global variable to log information
In the code we just did, we wrote the code System.out.println(“blabla”). This is fine but let us imagine you want to log somewhere else, it is not possible. One good practice is to use global variables for that purpose. We first define a java class called OutputDisplay that we shall create in the util package in src/main/java

Now we shall update the lesson1.drl file

The keyword global is used and then a normal java declaration. Here the global is of type OutputDisplay and the variable is called showResults. This variable can now be used in the “them” part of the rule as here.
To initialize the global variable, we shall use the method “setGlobal” on the session we create as shown here in our test :

When running the Junit test, the console should look like this :

最后
以上就是耍酷画笔最近收集整理的关于Drools Using a Global variable to log information的全部内容,更多相关Drools内容请搜索靠谱客的其他文章。
发表评论 取消回复