From e3b3d136d808dc0f1d9075f23a89037ec0efefa0 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 10 Apr 2021 22:03:44 +0200 Subject: [PATCH] Fix use search instead of match to filter logs (#49017) --- homeassistant/components/logger/__init__.py | 2 +- tests/components/logger/test_init.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/logger/__init__.py b/homeassistant/components/logger/__init__.py index fb2920fb6e2..c7660f2a3f0 100644 --- a/homeassistant/components/logger/__init__.py +++ b/homeassistant/components/logger/__init__.py @@ -114,7 +114,7 @@ def _add_log_filter(logger, patterns): """Add a Filter to the logger based on a regexp of the filter_str.""" def filter_func(logrecord): - return not any(p.match(logrecord.getMessage()) for p in patterns) + return not any(p.search(logrecord.getMessage()) for p in patterns) logger.addFilter(filter_func) diff --git a/tests/components/logger/test_init.py b/tests/components/logger/test_init.py index d2b0e8931b6..6435ef95394 100644 --- a/tests/components/logger/test_init.py +++ b/tests/components/logger/test_init.py @@ -42,6 +42,7 @@ async def test_log_filtering(hass, caplog): "doesntmatchanything", ".*shouldfilterall.*", "^filterthis:.*", + "in the middle", ], "test.other_filter": [".*otherfilterer"], }, @@ -62,6 +63,7 @@ async def test_log_filtering(hass, caplog): filter_logger, False, "this line containing shouldfilterall should be filtered" ) msg_test(filter_logger, True, "this line should not be filtered filterthis:") + msg_test(filter_logger, False, "this in the middle should be filtered") msg_test(filter_logger, False, "filterthis: should be filtered") msg_test(filter_logger, False, "format string shouldfilter%s", "all") msg_test(filter_logger, True, "format string shouldfilter%s", "not")