Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2021.4.4 #49139

Merged
merged 17 commits into from
Apr 13, 2021
Merged

2021.4.4 #49139

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix use search instead of match to filter logs (#49017)
  • Loading branch information
frenck authored and balloob committed Apr 13, 2021
commit e3b3d136d808dc0f1d9075f23a89037ec0efefa0
2 changes: 1 addition & 1 deletion homeassistant/components/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions tests/components/logger/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async def test_log_filtering(hass, caplog):
"doesntmatchanything",
".*shouldfilterall.*",
"^filterthis:.*",
"in the middle",
],
"test.other_filter": [".*otherfilterer"],
},
Expand All @@ -62,6 +63,7 @@ def msg_test(logger, result, message, *args):
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")
Expand Down