mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Ensure original log handlers are restored at close (#49230)
Error messages after close were not being logged
This commit is contained in:
parent
055cdc64c0
commit
d71f913a12
@ -77,6 +77,9 @@ def async_activate_log_queue_handler(hass: HomeAssistant) -> None:
|
|||||||
@callback
|
@callback
|
||||||
def _async_stop_queue_handler(_: Any) -> None:
|
def _async_stop_queue_handler(_: Any) -> None:
|
||||||
"""Cleanup handler."""
|
"""Cleanup handler."""
|
||||||
|
# Ensure any messages that happen after close still get logged
|
||||||
|
for original_handler in migrated_handlers:
|
||||||
|
logging.root.addHandler(original_handler)
|
||||||
logging.root.removeHandler(queue_handler)
|
logging.root.removeHandler(queue_handler)
|
||||||
listener.stop()
|
listener.stop()
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.const import EVENT_HOMEASSISTANT_CLOSE
|
||||||
from homeassistant.core import callback, is_callback
|
from homeassistant.core import callback, is_callback
|
||||||
import homeassistant.util.logging as logging_util
|
import homeassistant.util.logging as logging_util
|
||||||
|
|
||||||
@ -65,11 +66,18 @@ async def test_logging_with_queue_handler():
|
|||||||
async def test_migrate_log_handler(hass):
|
async def test_migrate_log_handler(hass):
|
||||||
"""Test migrating log handlers."""
|
"""Test migrating log handlers."""
|
||||||
|
|
||||||
|
original_handlers = logging.root.handlers
|
||||||
|
|
||||||
logging_util.async_activate_log_queue_handler(hass)
|
logging_util.async_activate_log_queue_handler(hass)
|
||||||
|
|
||||||
assert len(logging.root.handlers) == 1
|
assert len(logging.root.handlers) == 1
|
||||||
assert isinstance(logging.root.handlers[0], logging_util.HomeAssistantQueueHandler)
|
assert isinstance(logging.root.handlers[0], logging_util.HomeAssistantQueueHandler)
|
||||||
|
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_CLOSE)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert logging.root.handlers == original_handlers
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.no_fail_on_log_exception
|
@pytest.mark.no_fail_on_log_exception
|
||||||
async def test_async_create_catching_coro(hass, caplog):
|
async def test_async_create_catching_coro(hass, caplog):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user