First, for the logging level of bindings you can set the level by navigating to Settings → Bindings → Binding Name and click the little gear icon in the upper right or through the REST API or through the Karaf Console, or by editing log4j2.xml.
Unfortunately the REST API doesn’t support changing any other logger’s logging level so you’ll have to change those using the Karaf console, or by editing log4j2.xml and adding a new Logger to the bottom and setting the level there.
JS Scripting also supports setting the logging level in the rule itself.
To set the logger’s level in the Karaf Console or by editing the log4j2.xml file you’ll need to know the name of the logger you want to adjust.
Note: in JS Scripting console.trace will also log out a tiny stack trace of the call stack up to that point, so don’t treat it as simply a level below DEBUG, it has another purpose.
oh, that’s cool, didn’t know that - I always went right into the Karaf Console.
But - what I really meant was just to add some Rules-Logging:
some
console.info("here some info values: " + INFOVARIABLE);
rule
console.debug("here some debug values: " + DEBUGVARIABLE);
code
...
What I want is to leave the rule “as is”, but print the console.debug values only to the logs, if I want to really debug my rules, not 24/7.
But I think I found it here:
log:set debug org.openhab.core.model.script should do it then.
But: Is there a JS Scripting equivalent for logging a “subpackage” in DLS with logError("heating", "This is a log entry of type Error!"), meaning I could set only the “heating” logs to e.g. DEBUG?
Read my full reply. Everything after the first paragraph is about logging in rules. Logging level is controlled by logger name and I show how to change the name of the logger used in a given rule.
Sorry, I missed that. Thought org.openhab.core.model.script would change the logLevel already as it it already in my log4j2.xml.
I know nothing about log4j, so I just add a line after the last one?
Then I can set the LogLevel of that logger in the Karaf Console or inside the rule itself? Log4j 2 automatically reloads the log4j2.xml - at least Apacha says so: https://logging.apache.org/log4j/log4j-2.3/
But I still get:
2023-02-15 16:16:49.946 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'EMS_HauptProgramm' failed: org.graalvm.polyglot.PolyglotException: TypeError: (intermediate value).myRulesName is not a function
That gives the logger it’s name. In this case, on the Karaf Console, or in the log4j2.xml file that’s the name I’d use for the “name” of the logger.
But that doesn’t change how console works. You still use console.info("blah blah blah");, console.debug("blah blah blah"); and so on.
And I cannot stress this enough. Any time you have a question about how to do something in JS Scripting, review the JS Scripting’s add-on docs. They are astonishingly complete and comprehensive. The answer to almost every question will be there. In this particular case: JavaScript Scripting - Automation | openHAB
and with that set, I get iwith the following console-commands:
console.info("a INFO logentry");
console.debug("a DEGUB logentry");
console.info("a INFO logentry again");
2023-02-15 17:23:52.070 [INFO ] [tomation.script.ui.TestRule] - a INFO logentry
2023-02-15 17:23:52.071 [DEBUG] [tomation.script.ui.TestRule] - a DEBUG logentry
2023-02-15 17:23:52.073 [INFO ] [tomation.script.ui.TestRule] - a INFO logentry again
and of course the DEBUG logentry is gone, if I set log:set INFO org.openhab.automation.script in e.g. the console