diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py index 7d1088eebe493cc51a661f25acb7cf161221720f..145bb42af5bfe69a0caa9d27e418f47213d56154 100644 --- a/homeassistant/helpers/script.py +++ b/homeassistant/helpers/script.py @@ -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: diff --git a/tests/helpers/test_script.py b/tests/helpers/test_script.py index eb1d5e15020390ba8381531d37ed93528dcc9d87..9d7e7751c108d6057d0fa595e71fb57f010a68e7 100644 --- a/tests/helpers/test_script.py +++ b/tests/helpers/test_script.py @@ -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