Skip to content

Conversation

@aacic
Copy link
Collaborator

@aacic aacic commented Apr 23, 2025

Unnecessary logging was introduced in the #897

The error log now appears in the console on every WSI read.

@aacic aacic requested a review from shaneahmed April 23, 2025 16:13
@codecov
Copy link

codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.70%. Comparing base (bae6c2e) to head (bec136e).
Report is 17 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #924      +/-   ##
===========================================
- Coverage    99.70%   99.70%   -0.01%     
===========================================
  Files           71       71              
  Lines         8848     8847       -1     
  Branches      1154     1154              
===========================================
- Hits          8822     8821       -1     
  Misses          23       23              
  Partials         3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shaneahmed
Copy link
Member

shaneahmed commented Apr 24, 2025

Hi @aacic, Have you tried using DuplicateFilter?

class DuplicateFilter(logging.Filter):
"""Define an object to filter duplicate logs.
The DuplicateFilter filters logs to avoid printing them multiple times
while running code in a loop.
"""
def filter(self: DuplicateFilter, record: LogRecord) -> bool:
"""Filter input record."""
current_log = (record.module, record.levelno, record.msg)
if current_log != getattr(self, "last_log", None):
self.last_log = current_log
return True
return False
. This will remove additional responses.
I can merge this PR if you think DuplicateFilter will not be useful.

Here is example usage:

def test_duplicate_filter(caplog: pytest.LogCaptureFixture) -> None:
"""Test DuplicateFilter for warnings."""
# Test logger reset after applying duplicate filter.
duplicate_filter = DuplicateFilter()
logger.addFilter(duplicate_filter)
# Reset filters in logger.
for filter_ in logger.filters[:]:
logger.removeFilter(filter_)
for _ in range(2):
logger.warning("Test duplicate filter warnings.")
assert "Test duplicate filter warnings." in caplog.text
assert "\n" in caplog.text[:-2]
caplog.clear()
duplicate_filter = DuplicateFilter()
logger.addFilter(duplicate_filter)
for _ in range(2):
logger.warning("Test duplicate filter warnings.")
logger.removeFilter(duplicate_filter)
assert "Test duplicate filter warnings." in caplog.text
assert "\n" not in caplog.text[:-2]

@shaneahmed shaneahmed changed the title Remove unnecessary logging. 🔇 Remove Unnecessary Logging Apr 24, 2025
@shaneahmed shaneahmed added this to the Release v1.7.0 milestone Apr 24, 2025
@aacic
Copy link
Collaborator Author

aacic commented Apr 24, 2025

Hi @aacic, Have you tried using DuplicateFilter?

class DuplicateFilter(logging.Filter):
"""Define an object to filter duplicate logs.
The DuplicateFilter filters logs to avoid printing them multiple times
while running code in a loop.
"""
def filter(self: DuplicateFilter, record: LogRecord) -> bool:
"""Filter input record."""
current_log = (record.module, record.levelno, record.msg)
if current_log != getattr(self, "last_log", None):
self.last_log = current_log
return True
return False

. This will remove additional responses.
I can merge this PR if you think DuplicateFilter will not be useful.
Here is example usage:

def test_duplicate_filter(caplog: pytest.LogCaptureFixture) -> None:
"""Test DuplicateFilter for warnings."""
# Test logger reset after applying duplicate filter.
duplicate_filter = DuplicateFilter()
logger.addFilter(duplicate_filter)
# Reset filters in logger.
for filter_ in logger.filters[:]:
logger.removeFilter(filter_)
for _ in range(2):
logger.warning("Test duplicate filter warnings.")
assert "Test duplicate filter warnings." in caplog.text
assert "\n" in caplog.text[:-2]
caplog.clear()
duplicate_filter = DuplicateFilter()
logger.addFilter(duplicate_filter)
for _ in range(2):
logger.warning("Test duplicate filter warnings.")
logger.removeFilter(duplicate_filter)
assert "Test duplicate filter warnings." in caplog.text
assert "\n" not in caplog.text[:-2]

@shaneahmed IMO it shouldn't be logged at all, it is a leftover while I was debugging the code. I just want to remove it.

@shaneahmed shaneahmed merged commit 7ba7394 into TissueImageAnalytics:develop Apr 25, 2025
14 checks passed
aacic added a commit to aacic/tiatoolbox that referenced this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants