Slf4j Log4j logger not working with Drools (6.1.0.Beta2) drl while using as a global variable.

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Slf4j Log4j logger not working with Drools (6.1.0.Beta2) drl while using as a global variable.

Soumya.plavaga
This post was updated on .
I am using global slf4j log4j logger as a global variable within our drl and inserting that global logger value at runtime into kiesession. While we are trying to do logger.info with multiple arguments then it's giving the following exception stack trace -

Exception executing consequence for rule "Test Logger 2" in test.rules.system: java.lang.RuntimeException: cannot invoke method: info
        at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
        at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1027)
        at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:129)
        at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:71)
        at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:935)
        at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1200)
        at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:952)
        at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:926)
        at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:232)
        at test.platform.rules.executor.service.impl.RuleExecutorServiceImplTest.testExecuteRule(RuleExecutorServiceImplTest.java:230)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.RuntimeException: cannot invoke method: info
        at org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:63)
        at org.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
        at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
        at org.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
        at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
        at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
        at org.mvel2.MVEL.executeExpression(MVEL.java:930)
        at org.drools.core.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:107)
        at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1016)
        ... 36 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
        at org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(MethodAccessor.java:140)
        at org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
        ... 44 more


Example: My drl file looks like this -

package test.system.rule;

import test.platform.model.*;
import org.slf4j.Logger;

global Logger logger;

rule "Test Logger 1"

when

then

logger.info("within test logger 1");

end

rule "Test Logger 2"

when

then

logger.info("within test logger 2. Rule fired {}", drools.getRule().getName());

end


While rules are firing then the first logger is getting printed into console but second one is not getting printed and giving the above exception to me.

I am using Drools 6.1.0.Beta2.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Slf4j Log4j logger not working with Drools drl while using as a global variable.

ge0ffrey
Administrator
Check if the logger isn't null (by adding a System.out in the then part
of the rule).

If that's the case, then that error message is pretty poor (or even
incorrect):
    java.lang.RuntimeException: cannot invoke method: info
It should clearly talk about a NullPointer instead.
So, if that's the case, create a jira issue.
   https://issues.jboss.org/browse/DROOLS


On 27-05-14 07:09, Soumya.plavaga wrote:

> I am using global slf4j log4j logger as a global variable within our drl and
> inserting that global logger value at runtime into kiesession. While we are
> trying to do logger.info with multiple arguments then it's giving the
> following exception stack trace -
>
> Exception executing consequence for rule "Test Logger 2" in
> test.rules.system: java.lang.RuntimeException: cannot invoke method: info
> at
> org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
> at
> org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1027)
> at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:129)
> at
> org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:71)
> at
> org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:935)
> at
> org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1200)
> at
> org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:952)
> at
> org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:926)
> at
> org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:232)
> at
> test.platform.rules.executor.service.impl.RuleExecutorServiceImplTest.testExecuteRule(RuleExecutorServiceImplTest.java:230)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at
> org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
> at
> org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
> at
> org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
> at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
> at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> at
> org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
> at
> org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: java.lang.RuntimeException: cannot invoke method: info
> at
> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:63)
> at
> org.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
> at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
> at org.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
> at
> org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
> at
> org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
> at org.mvel2.MVEL.executeExpression(MVEL.java:930)
> at
> org.drools.core.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:107)
> at
> org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1016)
> ... 36 more
> Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
> at
> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(MethodAccessor.java:140)
> at
> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
> ... 44 more
>
>
> Example: My drl file looks like this -
>
> package test.system.rule;
>
> import test.platform.model.*;
> import org.slf4j.Logger;
>
> global Logger logger;
>
> rule "Test Logger 1"
>
> when
>
> then
>
> logger.info("within test logger 1");
>
> end
>
> rule "Test Logger 2"
>
> when
>
> then
>
> logger.info("within test logger 2. Rule fired {}",
> drools.getRule().getName());
>
> end
>
>
> While rules are firing then the first logger is getting printed into console
> but second one is not getting printed and giving the above exception to me.
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Slf4j-Log4j-logger-not-working-with-Drools-drl-while-using-as-a-global-variable-tp4029707.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Slf4j Log4j logger not working with Drools drl while using as a global variable.

laune
@Geoffrey: did you see the java.lang.ArrayIndexOutOfBoundsException?
Doesn't look like a null pointer causing an exception. The upstairs
exception might add the basic exceptions's message to its message.

@Soumya: Which Drools version are you using? Basically, this situation
is handled correctly by 5.4 and 5.5.

-W

On 27/05/2014, Geoffrey De Smet <[hidden email]> wrote:

> Check if the logger isn't null (by adding a System.out in the then part
> of the rule).
>
> If that's the case, then that error message is pretty poor (or even
> incorrect):
>     java.lang.RuntimeException: cannot invoke method: info
> It should clearly talk about a NullPointer instead.
> So, if that's the case, create a jira issue.
>    https://issues.jboss.org/browse/DROOLS
>
>
> On 27-05-14 07:09, Soumya.plavaga wrote:
>> I am using global slf4j log4j logger as a global variable within our drl
>> and
>> inserting that global logger value at runtime into kiesession. While we
>> are
>> trying to do logger.info with multiple arguments then it's giving the
>> following exception stack trace -
>>
>> Exception executing consequence for rule "Test Logger 2" in
>> test.rules.system: java.lang.RuntimeException: cannot invoke method: info
>> at
>> org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
>> at
>> org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1027)
>> at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:129)
>> at
>> org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:71)
>> at
>> org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:935)
>> at
>> org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1200)
>> at
>> org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:952)
>> at
>> org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:926)
>> at
>> org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:232)
>> at
>> test.platform.rules.executor.service.impl.RuleExecutorServiceImplTest.testExecuteRule(RuleExecutorServiceImplTest.java:230)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:606)
>> at
>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
>> at
>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>> at
>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
>> at
>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>> at
>> org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
>> at
>> org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
>> at
>> org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
>> at
>> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
>> at
>> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
>> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
>> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
>> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
>> at
>> org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
>> at
>> org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
>> at
>> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
>> at
>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>> at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>> Caused by: java.lang.RuntimeException: cannot invoke method: info
>> at
>> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:63)
>> at
>> org.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
>> at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
>> at org.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
>> at
>> org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
>> at
>> org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
>> at org.mvel2.MVEL.executeExpression(MVEL.java:930)
>> at
>> org.drools.core.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:107)
>> at
>> org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1016)
>> ... 36 more
>> Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
>> at
>> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(MethodAccessor.java:140)
>> at
>> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
>> ... 44 more
>>
>>
>> Example: My drl file looks like this -
>>
>> package test.system.rule;
>>
>> import test.platform.model.*;
>> import org.slf4j.Logger;
>>
>> global Logger logger;
>>
>> rule "Test Logger 1"
>>
>> when
>>
>> then
>>
>> logger.info("within test logger 1");
>>
>> end
>>
>> rule "Test Logger 2"
>>
>> when
>>
>> then
>>
>> logger.info("within test logger 2. Rule fired {}",
>> drools.getRule().getName());
>>
>> end
>>
>>
>> While rules are firing then the first logger is getting printed into
>> console
>> but second one is not getting printed and giving the above exception to
>> me.
>>
>>
>>
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/Slf4j-Log4j-logger-not-working-with-Drools-drl-while-using-as-a-global-variable-tp4029707.html
>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Slf4j Log4j logger not working with Drools drl while using as a global variable.

Soumya.plavaga
In reply to this post by ge0ffrey
> Check if the logger isn't null (by adding a System.out in the then part
> of the rule).

We checked, logger is not null here.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Slf4j Log4j logger not working with Drools drl while using as a global variable.

Soumya.plavaga
In reply to this post by laune
> @Soumya: Which Drools version are you using? Basically, this situation
> is handled correctly by 5.4 and 5.5.

We are using Drools version 6.1.0.Beta2.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Slf4j Log4j logger not working with Drools drl while using as a global variable.

tari-manga
This post was updated on .
I wonder if OP Soumya solved the issue, because at least in my case it is indeed working fine - I just tested with 610Final as we also wanted to log from rule via slf4j.

I attach demo that at least for us proves working.

I've also tried back-port the same project attached to test with 610beta2, and is working as well at least for me; although you need to be aware switch the 'packaging' to see the log in eclipse (ref. https://issues.jboss.org/browse/DROOLS-495)

Am I missing something?
OP Soumya did you solved your issue?
Thanks.
Ciao