Fix use search instead of match to filter logs (#49017)
parent
654a532641
commit
5983fac5c2
|
@ -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)
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue