The helper libraries provide several ways to produce log output in openHAB. This can be useful for providing information or error messages from your scripts to help diagnose issues. In some of the following examples, the logger can be modified to wherever you want the log to go. The default logger used in the modules and scripts is ‘jsr223.<language name>’, which is pulled from the value assigned to the LOG_PREFIX variable in the configuration library. If this is modified, be sure to configure your logging to include the logger chosen.
ruledecorator adds a logger attribute to the function or class that it is decorating.
It is also possible to create a logger using the
core.loglibrary to be used by all functions in a script or library.
The openHAB LogAction, as used in the Rules DSL, can be imported and used to write to the logs from a script or rule. Since LogAction uses SLF4J, it supports parameterized logging. Parameterized logging is beneficial, since the values in the parameters are not processed unless the logger is visible in the current logging level. This means that the complicated logging you do in
debugdoes not affect the performance of your system when the logging level is set to
As an alternative to using
core.log, you can access
SLF4Jdirectly in a similar manner. SLF4J supports parameterized logging.