18.13. Creating Audit Logs

Procedure 18.5. Task

  1. To create an audit log, execute the rules engine. You will be given the option of creating a new audit log.
  2. Enter the following code:
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    // Create a new Knowledge Runtime Logger, that logs to file.
    // An event.log file is created in the subdirectory log dir (which must exist) of the working directory
    KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger( ksession, "log/event");
    
    ksession.insert(...);
    ksession.fireAllRules();
    
    // stop logging
    logger.close();
  3. Open the log by clicking the Open Log action, the first icon in the Audit View, and select the file. The Audit View now shows all events that where logged during the executing of the rules.