Enable logging from Rules/Scripts

  • Platform information:
    • Hardware: Intel core i5/16GB/500GB
    • OS: macOS 10.13.6
    • Java Runtime Environment: OpenJDK Runtime Environment Zulu11.45+27-CA (build 11.0.10+9-LTS)
    • openHAB version: 3.0.1
  • Issue of the topic: I’m new on openHAB3, but have now successfully configured several “Things” and “Items”. I’m now working with rules and I want to log certain things to see what is going on.
    I have created a very simple rule that fires when the light in a room goes to OFF
    It executes a script ( application/vnd.openhab.dsl.rule ) which has only this one line:

logInfo("test", "The lights went off")

I’m looking into /userdata/logs/openhab.log

Sometimes I have seen messages being logged here, but mostly it is not appearing.

I have looked into /userdata/etc/log4j2.xml and added:

	<Logger level="INFO" name="org.openhab.core.model.script.test"/>

What am I doing wrong?

Then the most likely cause is the rule is not running or something else is wrong. I’d remove the changes you made to the log4j.xml file and post your full rule (click on the “code” tab) along with the events.log and openhab.log when you expect to see the log statement appear in openhab.log.

Use code fences for both.

```
code or logs go here
```

I restored the original log4j.xml

It seems to work now as expected. This is a bit strange because I could have sworn that I have tried many different times and nothing showed up in the logs.

But maybe I had some bug somewhere all along :frowning:

events.log:

2021-03-18 21:32:26.481 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'netatmo:NAModule1:home:outside' changed from OFFLINE: Pending parent object initialization to ONLINE
2021-03-18 21:32:26.484 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'netatmo:NAModule3:home:rain' changed from OFFLINE: Pending parent object initialization to ONLINE
2021-03-18 21:34:09.671 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Vaerksted_Lys' received command OFF
2021-03-18 21:34:09.681 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Vaerksted_Lys' predicted to become OFF
2021-03-18 21:34:09.686 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Vaerksted_Lys' changed from ON to OFF
2021-03-18 21:34:21.632 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'NetatmoInside_CO2' changed from 673 ppm to 688 ppm
2021-03-18 21:34:21.636 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'NetatmoInside_Temperature' changed from 24.5 °C to 24.6000003814697265625 °C
2021-03-18 21:34:21.637 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'NetatmoOutside_Temperature' changed from 3.5 °C to 3.400000095367431640625 °C
2021-03-18 21:34:22.593 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Vaerksted_Lys' received command ON
2021-03-18 21:34:22.594 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Vaerksted_Lys' predicted to become ON
2021-03-18 21:34:22.596 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Vaerksted_Lys' changed from OFF to ON
2021-03-18 21:34:43.147 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Vaerksted_Lys' received command OFF
2021-03-18 21:34:43.149 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Vaerksted_Lys' predicted to become OFF
2021-03-18 21:34:43.152 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Vaerksted_Lys' changed from ON to OFF
2021-03-18 21:34:44.048 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Vaerksted_Lys' received command ON
2021-03-18 21:34:44.050 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Vaerksted_Lys' predicted to become ON
2021-03-18 21:34:44.052 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Vaerksted_Lys' changed from OFF to ON

openhab.log:

2021-03-18 21:32:21.401 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.
2021-03-18 21:34:09.990 [INFO ] [org.openhab.core.model.script.test  ] - The light went out
2021-03-18 21:34:11.403 [WARN ] [io.openhabcloud.internal.CloudClient] - Jetty request 14551853 failed: null
2021-03-18 21:34:11.404 [WARN ] [io.openhabcloud.internal.CloudClient] - Response Failure: null
2021-03-18 21:34:43.175 [INFO ] [org.openhab.core.model.script.test  ] - The light went out