Rule Logging Test

I wrote a stupid rule to see whether logging can work in rules with the latest openhab core on the master branch. And I use the development environment to test it, which is the app.bndrun.

rule “TestLog”
when
Time cron “5 * * * * ?”
then
logWarn(“TestLog”, “Test Start!”)
logWarn(“TestLog”, “Test End!”)
end

Also I add the following logging entry in the logback.xml.

<logger name= "LogService" level= "WARN" />
<logger name= "org.openhab.model.script" level= "WARN" />
<logger name= "org.openhab.model.script" level= "WARN" />`
<logger name= "org.openhab.core.model.rule" level= "WARN" />
<logger name= "org.openhab.core.model.script" level= "WARN" />

However, I get the error like the following and I cannot see the test output like “Test Start!” in the console.

22:24:05.714 [ool-12-thread-1] ERROR o.o.c.m.s.r.i.engine.DSLScriptEngine:103 - Script references context ‘testLog-1’, but no context provider is registered!

Does anyone have any advice? Why can’t I use logWarn and get the output? By the way, I am using openhab core on the master branch.

This no longer exists… not only have all references to ESH in package names been changed over to the org.openhab namespace, but the old rule engine has also been removed.

You’ll want to start up at org.openhab.core.automation.

Hi 5iver, I tried org.openhab.core.automation but it doesn’t work either. Do you have any suggestion?

Did you restart? Changes to the logback.xml do not take effect until after a restart.

Yes, I close Eclipse and restart it again. It is so strange.

I didn’t mean to close Eclipse, but to stop OH and restart it :slightly_smiling_face:.

Just to be sure, you are updating the org.openhab.demo.app/runtim/logback.xml? Post the contents.

No, the path is org.openhab.demo.app/runtime/userdata/logback.xml. By the way, I inject RuleMananger, and use it to run the rule directly. However it shows me the following information.

17:58:16.093 [OH-stam-2] ERROR o.o.c.m.s.r.i.engine.DSLScriptEngine:103 - Script references context ''testLog-1", but no context provider is registered!

where testLog.rules is the name of the rule file. Any idea?

Double check… that is not where the file resides.

I wouldn’t be surprised if it was broken. Use scripted automation!

Yes you are right… The path is org.openhab.demo.app/runtime/logback.xml. The content is as follows.

By the way, RuleMananger is a service in the org.openhab.core.automation, and I injected it. I don’t get it when you say “use scripted automation”. Could you give me some hints?

https://openhab-scripters.github.io/openhab-helper-libraries/index.html

Set the logging level for org.openhab.automation to DEBUG and you will get lots of logs. For the rules DSL, try org.openhab.core.model.script.

Thanks. Both org.openhab.automation and org.openhab.core.automation have been tried, but still no progress… What a annoying issue!

Sorry, typo… org.openhab.core.automation. You’re logback.xml only had it set to WARN. Make sure you have the latest and make sure you have the new rule engine enabled. I may have been lumped in with a bunch of other changes, but I don;t recall a PR that specifically enabled it by default.

It is strange, because in my rule, I use logWarn. Actually setting to DEBUG level gives me a lot of log, and I didn’t find any log which is related to my rule…

I just saw the trigger you’re using. ‘System started’ had to be remade for the new rule engine and may not work yet. Try a cron trigger that fires every 5s.

That’s a huge progress. At least now there is a warnning message.

22:24:05.714 [ool-12-thread-1] ERROR o.o.c.m.s.r.i.engine.DSLScriptEngine:103 - Script references context ‘testLog-1’, but no context provider is registered!

So finally this problem comes out…

Hi… were you able to sort this context issue?