mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Allow excluding modules from noisy logs check (#142020)
* Allow excluding modules from noisy logs check * Cache non-excluded modules; hardcode self module name; optimize call * Address review comments
This commit is contained in:
@@ -160,6 +160,10 @@ async def test_catch_log_exception_catches_and_logs() -> None:
|
||||
|
||||
|
||||
@patch("homeassistant.util.logging.HomeAssistantQueueListener.MAX_LOGS_COUNT", 5)
|
||||
@patch(
|
||||
"homeassistant.util.logging.HomeAssistantQueueListener.EXCLUDED_LOG_COUNT_MODULES",
|
||||
["excluded"],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
(
|
||||
"logger1_count",
|
||||
@@ -182,6 +186,7 @@ async def test_noisy_loggers(
|
||||
logging_util.async_activate_log_queue_handler(hass)
|
||||
logger1 = logging.getLogger("noisy1")
|
||||
logger2 = logging.getLogger("noisy2.module")
|
||||
logger_excluded = logging.getLogger("excluded.module")
|
||||
|
||||
for _ in range(logger1_count):
|
||||
logger1.info("This is a log")
|
||||
@@ -189,6 +194,9 @@ async def test_noisy_loggers(
|
||||
for _ in range(logger2_count):
|
||||
logger2.info("This is another log")
|
||||
|
||||
for _ in range(logging_util.HomeAssistantQueueListener.MAX_LOGS_COUNT + 1):
|
||||
logger_excluded.info("This log should not trigger a warning")
|
||||
|
||||
await empty_log_queue()
|
||||
|
||||
assert (
|
||||
@@ -203,6 +211,33 @@ async def test_noisy_loggers(
|
||||
)
|
||||
== logger2_expected_notices
|
||||
)
|
||||
# Ensure that the excluded module did not trigger a warning
|
||||
assert (
|
||||
caplog.text.count("is logging too frequently")
|
||||
== logger1_expected_notices + logger2_expected_notices
|
||||
)
|
||||
|
||||
# close the handler so the queue thread stops
|
||||
logging.root.handlers[0].close()
|
||||
|
||||
|
||||
@patch("homeassistant.util.logging.HomeAssistantQueueListener.MAX_LOGS_COUNT", 1)
|
||||
async def test_noisy_loggers_ignores_self(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test that the noisy loggers warning does not trigger a warning for its own module."""
|
||||
|
||||
logging_util.async_activate_log_queue_handler(hass)
|
||||
logger1 = logging.getLogger("noisy_module1")
|
||||
logger2 = logging.getLogger("noisy_module2")
|
||||
logger3 = logging.getLogger("noisy_module3")
|
||||
|
||||
logger1.info("This is a log")
|
||||
logger2.info("This is a log")
|
||||
logger3.info("This is a log")
|
||||
|
||||
await empty_log_queue()
|
||||
assert caplog.text.count("logging too frequently") == 3
|
||||
|
||||
# close the handler so the queue thread stops
|
||||
logging.root.handlers[0].close()
|
||||
|
||||
Reference in New Issue
Block a user