Fix use search instead of match to filter logs (#49017)

pull/49030/head
Franck Nijhof 2021-04-10 22:03:44 +02:00 committed by GitHub
parent 654a532641
commit 5983fac5c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -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)

View File

@ -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")