mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 16:17:20 +00:00
Fix script logging with name (#33120)
This commit is contained in:
parent
95de94e53f
commit
7a6ac578b4
@ -701,7 +701,9 @@ class Script:
|
|||||||
|
|
||||||
def _log(self, msg, *args, level=logging.INFO):
|
def _log(self, msg, *args, level=logging.INFO):
|
||||||
if self.name:
|
if self.name:
|
||||||
msg = f"{self.name}: {msg}"
|
msg = f"%s: {msg}"
|
||||||
|
args = [self.name, *args]
|
||||||
|
|
||||||
if level == _LOG_EXCEPTION:
|
if level == _LOG_EXCEPTION:
|
||||||
self._logger.exception(msg, *args)
|
self._logger.exception(msg, *args)
|
||||||
else:
|
else:
|
||||||
|
@ -1743,3 +1743,15 @@ async def test_if_running_parallel(hass):
|
|||||||
assert len(events) == 4
|
assert len(events) == 4
|
||||||
assert events[2].data["value"] == 2
|
assert events[2].data["value"] == 2
|
||||||
assert events[3].data["value"] == 2
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user