[OH3] ECMA rules, logging

While porting my DSL rules to Javascript (ECMA) I “stumbled” over the suggestion to create a logger with this:
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleID);

That is working fine in most part, the ending ctx.ruleID however, which should get the UID of the rule ( in my humble understanding) remains undefined.
Am I missing a definition?

After reading the JSR222 Scripting Documentation I changed it to:

this.Rule = (this.Rule === undefined) ? Java.type("org.openhab.core.automation.Rule") : this.Rule;
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.'+ Rule.getUID());

However the result remains undefined.

Doing some more testing I found that the logging is WORKING using the single line defintion.

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleID);

however ONLY if the system generated UID of the rule is NOT changed!
Is this correct??

Finally I found it:
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
Note theU in ruleUID!

1 Like