Next-Gen Rules Javascript - Debug

Hi guys,

I’m successfully using the Next-Gen (Experimiental) rules in OpenHab with JavaScript scripting, and they work well, especially when designed using the FlowsBuilder UI. While this UI provides a clever way to start fast with these kinds of rules, overall debugging has been painful:

  • logInfo sentences do not work as I think this is a different context/rule engine.
  • I’ve seen sample JavaScript rules where they are using the print(‘something’); sentences, but I’m wondering where the output is actually written to. E.g. I’m using either the /var/logs/openhab2/events.log or the karaf console (log:tail), but I don’t receive the output there. I don’t know if I should increase the logging level to see something.

Could you guys describe what is the best method of debugging the experimental rules or help me finding out where I should receive the output of the JavaScript ‘print’ sentences?

You can just try the following solution for logging within a javascript rule/transformation:

var logger = Java.type("org.slf4j.LoggerFactory").getLogger("myScript");
logger.warn("test");

This will show up in /var/log/openhab2/openhab.log

8 Likes

Finally got some time to test this again. Your solution worked indeed. Thanks!

1 Like

Hi guys,

I’m not able to set the log, I’ve tried the solution above, and also tried to set via Karaf “log:set DEBUG org.eclipse.smarthome.transform.javascript”

Nothing :frowning:

Any clue? OH3.1.0 build 2331 here

thanks
Andrea