# Python logging question

**URL:** <https://community.openhab.org/t/python-logging-question/167922>\
**Category:** Other\
**Tags:** rules, python\
**Created:** [January 9, 2026, 2:34pm UTC](https://community.openhab.org/t/python-logging-question/167922 "2026-01-09T14:34:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![v61](https://community.openhab.org/letter_avatar_proxy/v4/letter/v/b9e5f3/32.png) [@v61](https://community.openhab.org/u/v61)\
**Post date:** [January 9, 2026, 2:34pm UTC](https://community.openhab.org/t/python-logging-question/167922/1 "2026-01-09T14:34:22Z")

</div>

Hi,

When I run this python test in OH 5.1.1:

```python
from openhab import logger

logger.info("logger is used")
print("print is used")

```

the result is this:

```bash
2026-01-09 15:23:00.013 [INFO] [g.openhab.automation.pythonscripting] - logger is used
2026-01-09 15:23:00.013 [INFO] [utomation.pythonscripting.71b019046e] - print is used

```

Is it not supposed to add the rule ID after “pythonscripting” in both methods?

I think (not sure) that it was like that in 5.0.

Best Regards, Valter

---

<div class="post-metadata">

**Author:** ![v61](https://community.openhab.org/letter_avatar_proxy/v4/letter/v/b9e5f3/32.png) [@v61](https://community.openhab.org/u/v61)\
**Post date:** [January 14, 2026, 7:09am UTC](https://community.openhab.org/t/python-logging-question/167922/2 "2026-01-14T07:09:12Z")

</div>

Never mind,

Using this instead:

```python
from openhab.actions import Log
def log_info(log_text): 
  Log.logInfo(ctx["ruleUID"], str(log_text))
  
def log_warn(log_text): 
  Log.logWarn(ctx["ruleUID"], str(log_text))

def log_debug(log_text): 
  Log.logDebug(ctx["ruleUID"], str(log_text))

def log_error(log_text): 
  Log.logError(ctx["ruleUID"], str(log_text))

```

Best Regards, Valter

---

<div class="post-metadata">

**Author:** ![holger\_hees](https://community.openhab.org/user_avatar/community.openhab.org/holger_hees/32/110860_2.png) [@holger\_hees](https://community.openhab.org/u/holger_hees)\
**Post date:** [January 14, 2026, 10:10am UTC](https://community.openhab.org/t/python-logging-question/167922/3 "2026-01-14T10:10:12Z")

</div>

@v61 you are right!

Looks like it happens only for UI based rules. I will check!

---

<div class="post-metadata">

**Author:** ![holger\_hees](https://community.openhab.org/user_avatar/community.openhab.org/holger_hees/32/110860_2.png) [@holger\_hees](https://community.openhab.org/u/holger_hees)\
**Post date:** [January 14, 2026, 12:26pm UTC](https://community.openhab.org/t/python-logging-question/167922/4 "2026-01-14T12:26:37Z")

</div>

@v61

The reason was that the prefix was generated when the module was imported.

With file-based rules, this happens when the rule is loaded and directly executed. This works as expected. However, with UI-based rules, the rule is precompiled or cached. At that point, the log prefix was already generated, even though the rule ID hadn’t yet been determined.

I’ve now implemented this in a [more “lazy” way](https://github.com/openhab/openhab-python/commit/e00b898ff704d285b4c6193feb367f13991c4109). This means the prefix is ​​generated the first time the logging object is used. This should fix the error.

If you want to test this, simply update to the [latest helper library version](https://github.com/openhab/openhab-python/releases/tag/1.0.17).

The easiest way to do this is via the [openHAB CLI](https://www.openhab.org/addons/automation/pythonscripting/#console). Just enter `pythonscripting update install latest`.

---

<div class="post-metadata">

**Author:** ![v61](https://community.openhab.org/letter_avatar_proxy/v4/letter/v/b9e5f3/32.png) [@v61](https://community.openhab.org/u/v61)\
**Post date:** [January 14, 2026, 1:43pm UTC](https://community.openhab.org/t/python-logging-question/167922/5 "2026-01-14T13:43:25Z")

</div>

Hi,

It works!

Best Regards, Valter
