Eiko Wagenknecht
Software Developer, Freelancer & Founder

Setting Logging Level in openHAB 3 Rules for Debugging

Eiko Wagenknecht

When a rule in openHAB 3 isn’t working correctly, adding additional debugging statements to the rule and increasing the log level can help you gain a more detailed insight into the error.

Table of Contents

Writing Logging Statements in Rules (DSL)

If you’re using the DSL language (the standard in openHAB 2, still widely used in openHAB 3) to write rules, you can use the following commands in the rule to generate log output:

Replace <scriptname> with a value of your choice. This value is particularly important because you can change the log level to be recorded for each entry here.

In the default setting, everything up to “Info” is logged, i.e., “Error”, “Warn”, and “Info”.

Example

This is how a rule with logging statements might look:

rule "Ventilation - Synchronize Items - Kitchen/Living Room"

when
  Item EG_Wohnen_Lueftung_Automatik changed or
  Item EG_Kueche_Lueftung_Automatik changed

then
  logDebug("sync", "Synchronizing status of EG_Wohnen_Lueftung_Automatik and EG_Kueche_Lueftung_Automatik: " + newState)

if(EG_Wohnen_Lueftung_Automatik.state != newState) {
  logDebug("sync", "Setting EG_Wohnen_Lueftung_Automatik to " + newState)
  EG_Wohnen_Lueftung_Automatik.sendCommand(newState.toString)
}

if(EG_Kueche_Lueftung_Automatik.state != newState) {
  logDebug("sync", "Setting EG_Kueche_Lueftung_Automatik to " + newState)
  EG_Kueche_Lueftung_Automatik.sendCommand(newState.toString)
}

end

Setting the Log Level

If you want to change the level (e.g., to also log “Debug”), connect to the openHAB Karaf console and run the command:

log:set <LEVEL> org.openhab.core.model.script.<scriptname>

For example:

log:set DEBUG org.openhab.core.model.script.helloworld

Possible values for <LEVEL> are (in ascending order, corresponding to the maximum log level to be recorded):

Resetting the Log Level

When all investigations are complete, the level can be reset to the default (logging up to INFO) with:

log:set DEFAULT org.openhab.core.model.script.<scriptname>

Or completely disabled with:

log:set OFF org.openhab.core.model.script.<scriptname>

Displaying the Current Log Level

All currently set levels are shown by the command:

log:list

Conclusion

I look forward to your comments on whether this article has been helpful. Feel free to write if you have questions or if something remains unclear. Or if you’ve been able to implement exciting further automation projects based on this!

No Comments? No Problem.

This blog doesn't support comments, but your thoughts and questions are always welcome. Reach out through the contact details in the footer below.

Support Me

If you found this page helpful and want to say thanks, I would be very grateful if you could use this link for your next purchase on amazon.com. I get a small commission, and it costs you nothing extra. If you'd like to support me in another way, you can find more options here.