mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Guard for doRollover failing (#55669)
This commit is contained in:
parent
7caa985a59
commit
e0f640c0f8
@ -342,7 +342,11 @@ def async_enable_logging(
|
|||||||
err_log_path, backupCount=1
|
err_log_path, backupCount=1
|
||||||
)
|
)
|
||||||
|
|
||||||
err_handler.doRollover()
|
try:
|
||||||
|
err_handler.doRollover()
|
||||||
|
except OSError as err:
|
||||||
|
_LOGGER.error("Error rolling over log file: %s", err)
|
||||||
|
|
||||||
err_handler.setLevel(logging.INFO if verbose else logging.WARNING)
|
err_handler.setLevel(logging.INFO if verbose else logging.WARNING)
|
||||||
err_handler.setFormatter(logging.Formatter(fmt, datefmt=datefmt))
|
err_handler.setFormatter(logging.Formatter(fmt, datefmt=datefmt))
|
||||||
|
|
||||||
|
@ -56,11 +56,14 @@ async def test_home_assistant_core_config_validation(hass):
|
|||||||
assert result is None
|
assert result is None
|
||||||
|
|
||||||
|
|
||||||
async def test_async_enable_logging(hass):
|
async def test_async_enable_logging(hass, caplog):
|
||||||
"""Test to ensure logging is migrated to the queue handlers."""
|
"""Test to ensure logging is migrated to the queue handlers."""
|
||||||
with patch("logging.getLogger"), patch(
|
with patch("logging.getLogger"), patch(
|
||||||
"homeassistant.bootstrap.async_activate_log_queue_handler"
|
"homeassistant.bootstrap.async_activate_log_queue_handler"
|
||||||
) as mock_async_activate_log_queue_handler:
|
) as mock_async_activate_log_queue_handler, patch(
|
||||||
|
"homeassistant.bootstrap.logging.handlers.RotatingFileHandler.doRollover",
|
||||||
|
side_effect=OSError,
|
||||||
|
):
|
||||||
bootstrap.async_enable_logging(hass)
|
bootstrap.async_enable_logging(hass)
|
||||||
mock_async_activate_log_queue_handler.assert_called_once()
|
mock_async_activate_log_queue_handler.assert_called_once()
|
||||||
mock_async_activate_log_queue_handler.reset_mock()
|
mock_async_activate_log_queue_handler.reset_mock()
|
||||||
@ -75,6 +78,8 @@ async def test_async_enable_logging(hass):
|
|||||||
for f in glob.glob("testing_config/home-assistant.log*"):
|
for f in glob.glob("testing_config/home-assistant.log*"):
|
||||||
os.remove(f)
|
os.remove(f)
|
||||||
|
|
||||||
|
assert "Error rolling over log file" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_load_hassio(hass):
|
async def test_load_hassio(hass):
|
||||||
"""Test that we load Hass.io component."""
|
"""Test that we load Hass.io component."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user