Fix use search instead of match to filter logs (#49017)
parent
0a5a5ff053
commit
e3b3d136d8
|
@ -114,7 +114,7 @@ def _add_log_filter(logger, patterns):
|
||||||
"""Add a Filter to the logger based on a regexp of the filter_str."""
|
"""Add a Filter to the logger based on a regexp of the filter_str."""
|
||||||
|
|
||||||
def filter_func(logrecord):
|
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)
|
logger.addFilter(filter_func)
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ async def test_log_filtering(hass, caplog):
|
||||||
"doesntmatchanything",
|
"doesntmatchanything",
|
||||||
".*shouldfilterall.*",
|
".*shouldfilterall.*",
|
||||||
"^filterthis:.*",
|
"^filterthis:.*",
|
||||||
|
"in the middle",
|
||||||
],
|
],
|
||||||
"test.other_filter": [".*otherfilterer"],
|
"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"
|
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, 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, "filterthis: should be filtered")
|
||||||
msg_test(filter_logger, False, "format string shouldfilter%s", "all")
|
msg_test(filter_logger, False, "format string shouldfilter%s", "all")
|
||||||
msg_test(filter_logger, True, "format string shouldfilter%s", "not")
|
msg_test(filter_logger, True, "format string shouldfilter%s", "not")
|
||||||
|
|
Loading…
Reference in New Issue