4.3. Events
Both the stateful and stateless knowledge sessions provide methods that allow you to register and remove listeners. Use
ProcessEventListener objects to listen to process-related events (like starting or completing a process or entering or leaving a node.) Here are the different methods for it:
You can create an audit log based on the information provided by these process listeners. Red Hat provides you with the following ones out-of the-box:
- Console logger: this outputs every event to the console.
- File logger: this outputs every event to an XML file. This log file might then be used in the IDE to generate a tree-based visualization of the events that occurred during execution.
- Threaded file logger: Because a file logger writes the events to disk only when closing the logger or when the number of events in the logger reaches a pre-defined threshold, it cannot be used when debugging processes at run-time. The threaded file logger writes the events to a file after a specified time interval, making it possible to use the logger to visualize progress in real-time, making it useful for debugging.
Use the
KnowledgeRuntimeLoggerFactory to add a logger to your session:
Note
When creating a console logger, pass the knowledge session for it as an argument.
The file logger must also be supplied requires the name of the log file to be created.
The threaded file logger requires the interval (in milliseconds) after which the events are to be saved.
You can open the log file in JBDS. To do so, go to the Audit View. Here you will see the events depicted in the form of a tree. (Anything that occurs between the
before and after events is shown as a child of that event.)