feat: replace print statements with structured logging#2154
Conversation
Co-authored-by: Borda <[email protected]>
Co-authored-by: Borda <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #2154 +/- ##
=======================================
Coverage 74% 74%
=======================================
Files 61 62 +1
Lines 7454 7486 +32
=======================================
+ Hits 5515 5547 +32
Misses 1939 1939 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR replaces print() statements with structured logging throughout the codebase. It introduces a new internal logging utility (_get_logger()) that configures loggers with separate stdout (INFO/DEBUG) and stderr (WARNING+) handlers. The changes improve observability and allow users to control log output via the LOG_LEVEL environment variable.
Changes:
- Created
src/supervision/utils/logger.pywith_get_logger()function for consistent logging configuration - Replaced
print()calls with appropriate logger methods (INFO for informational messages, WARNING for issues) - Updated tests to mock logger instead of
builtins.print
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/supervision/utils/logger.py |
New module providing _get_logger() function for creating configured loggers |
src/supervision/assets/downloader.py |
Replaced prints with logger.info (download progress) and logger.warning (file corruption) |
src/supervision/metrics/mean_average_precision.py |
Replaced print with logger.info for metric summary output |
src/supervision/utils/video.py |
Replaced print with logger.warning for codec fallback |
src/supervision/detection/tools/csv_sink.py |
Replaced print with logger.warning for field name mismatch |
src/supervision/annotators/core.py |
Replaced print with logger.warning for missing font path |
tests/assets/test_downloader.py |
Updated mocks and assertions to verify logger calls instead of print |
…g example Co-authored-by: Borda <[email protected]>
|
@copilot apply changes based on the comments in this thread |
Both items from that review were already applied in 7e815e6: the Example section was added to the |
All
print()calls in library code (excluding doctest examples) are replaced with a proper logger, following the same pattern used in rf-detr.New:
supervision/utils/logger.pyIntroduces
_get_logger()(private, internal use only) with:DEBUG/INFO→stdout;WARNING+ →stderrLOG_LEVELenv var (defaults toINFO)Log level assignments
assets/downloader.pyINFOassets/downloader.pyWARNINGutils/video.pyTypeError, falling back tomp4vWARNINGdetection/tools/csv_sink.pyWARNINGannotators/core.pyWARNINGmetrics/mean_average_precision.pyINFOTests
tests/utils/test_logger.py(new): 11 tests covering logger name, level,LOG_LEVELenv var, stdout/stderr handler configuration,propagate=False, and idempotency.tests/assets/test_downloader.py: updated to mocksupervision.assets.downloader.loggerinstead ofbuiltins.print; the corrupted-file test now usesside_effect=[False, True]onis_md5_hash_matchingso the real code path (includinglogger.warning) is exercised and asserted.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.