droolsdrools-guvnordrools-kie-serverdrools-kie-workbench

How can I trace drools rule execution in KIE server?


How can I enable rule engine tracing/logging when the rule application is running on KIE server?

The rule application was created in the Workbench, and contains no custom code. I am able to execute the rules using the KIE REST API, but the rule app is not producing the expected results.

Environment:

Win7

Tomcat 9

Drools 6.5.0-Final

Update:

I have tried the following steps:

  1. Clone the workbench project locally using git
  2. Add logback.xml to the project's root directory
  3. Push changes back to the workbench git repo
  4. Added logback as a dependency in the workbench Project Editor view
  5. Update project version and redeploy to the container

When I do this, it ignores my logging settings, but spams log messages endlessly to the console, telling me that it can't instantiate logback classes:

20-Jun-2017 16:58:29.070 WARNING [http-nio-8080-exec-5] org.kie.server.services.drools.DroolsKieServerExtension.createContainer Unable to create instance of type ch.qos.logback.classic.selector.C
ontextSelector due to ch.qos.logback.classic.selector.ContextSelector
20-Jun-2017 16:58:29.083 WARNING [http-nio-8080-exec-5] org.kie.server.services.drools.DroolsKieServerExtension.createContainer Unable to create instance of type ch.qos.logback.classic.selector.C
ontextJNDISelector due to ch.qos.logback.classic.selector.ContextJNDISelector
20-Jun-2017 16:58:29.101 WARNING [http-nio-8080-exec-5] org.kie.server.services.drools.DroolsKieServerExtension.createContainer Unable to create instance of type ch.qos.logback.classic.selector.D
efaultContextSelector due to ch.qos.logback.classic.selector.DefaultContextSelector

Solution

  • Add the following jars to tomcat's /lib folder:

     logback-classic-1.1.3.jar
     logback-core-1.1.3.jar
     slf4j-api-1.7.2.jar
     slf4j-ext-1.7.2.jar
    

    (Can't remember if the slf4j jars were already there, or if I added them.)

    For Windows, create a text file bin/setenv.bat if none exists.

    In setenv.bat, add the following settings:

    set "JAVA_OPTS=%JAVA_OPTS% -Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener -Dlogback.configurationFile="%CATALINA_HOME%\conf\logback.groovy""
    

    These console listener instructs logback to tell you if your logback config is wrong. The other setting is the location of your logback config file.

    For tracing rules, my logback.groovy looks something like this:

    import java.nio.charset.Charset
    
    appender('STDOUT', ConsoleAppender) {
        encoder(PatternLayoutEncoder) {
            charset = Charset.forName('UTF-8')
    
            pattern = "%d{HH:mm:ss.SSS} %-5level %logger{5} - %msg%n"
        }
    }
    
    appender('STDOUT-SHORT', ConsoleAppender) {
        encoder(PatternLayoutEncoder) {
            charset = Charset.forName('UTF-8')
    
            pattern = "%d{HH:mm:ss.SSS} - %msg%n"
        }
    }
    
    root(WARN, ["STDOUT"])
    
    logger("org.apache", WARN, ["STDOUT"], false)
    logger("org.kie.server", WARN, ["STDOUT"], false)
    logger("org.kie.server.controller", DEBUG, ["STDOUT"], false)
    logger("org.guvnor.common.services.builder.IncrementalBuilderExecutorManagerFactoryImpl", ERROR, ["STDOUT"], false)
    logger("bitronix", ERROR, ["STDOUT"], false)
    
    logger("org.kie.api.event.rule", TRACE, ["STDOUT"], false)
    logger("org.drools.core", TRACE, ["STDOUT-SHORT"], false)
    logger("org.uberfire.commons.async.SimpleAsyncExecutorService", ERROR, ["STDOUT"], false)
    

    These settings produce spammy and cryptic but useful output from the KIE Server and the Workbench.