Skip to content
Snippets Groups Projects
Unverified Commit f95c3e26 authored by Paulus Schoutsen's avatar Paulus Schoutsen Committed by GitHub
Browse files

Fix script logging with name (#33120)

parent 66402b9b
No related branches found
No related tags found
No related merge requests found
......@@ -817,7 +817,9 @@ class Script:
def _log(self, msg, *args, level=logging.INFO):
if self.name:
msg = f"{self.name}: {msg}"
msg = f"%s: {msg}"
args = [self.name, *args]
if level == _LOG_EXCEPTION:
self._logger.exception(msg, *args)
else:
......
......@@ -1138,3 +1138,15 @@ async def test_script_mode_queue(hass):
assert not script_obj.is_running
assert len(events) == 4
assert events[3].data["value"] == 2
async def test_script_logging(caplog):
"""Test script logging."""
script_obj = script.Script(None, [], "Script with % Name")
script_obj._log("Test message with name %s", 1)
assert "Script with % Name: Test message with name 1" in caplog.text
script_obj = script.Script(None, [])
script_obj._log("Test message without name %s", 2)
assert "Test message without name 2" in caplog.text
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment