Skip to content

feat: replace print statements with structured logging#2154

Merged
Borda merged 6 commits intodevelopfrom
copilot/implement-logging-system
Feb 20, 2026
Merged

feat: replace print statements with structured logging#2154
Borda merged 6 commits intodevelopfrom
copilot/implement-logging-system

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

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.py

Introduces _get_logger() (private, internal use only) with:

  • DEBUG/INFOstdout; WARNING+ → stderr
  • Configurable via LOG_LEVEL env var (defaults to INFO)
  • Idempotent — safe to call multiple times without adding duplicate handlers

Log level assignments

Location Message Level
assets/downloader.py Download start / complete INFO
assets/downloader.py MD5 integrity failure WARNING
utils/video.py Codec TypeError, falling back to mp4v WARNING
detection/tools/csv_sink.py Field name mismatch on append WARNING
annotators/core.py Font path not found, using default WARNING
metrics/mean_average_precision.py AP/AR summary rows INFO

Tests

  • tests/utils/test_logger.py (new): 11 tests covering logger name, level, LOG_LEVEL env var, stdout/stderr handler configuration, propagate=False, and idempotency.
  • tests/assets/test_downloader.py: updated to mock supervision.assets.downloader.logger instead of builtins.print; the corrupted-file test now uses side_effect=[False, True] on is_md5_hash_matching so the real code path (including logger.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.

Copilot AI changed the title [WIP] Implement logging system and replace print statements feat: replace print statements with structured logging Feb 20, 2026
Copilot AI requested a review from Borda February 20, 2026 10:52
Copilot AI requested a review from Borda February 20, 2026 11:08
@Borda Borda marked this pull request as ready for review February 20, 2026 11:35
@Borda Borda requested a review from SkalskiP as a code owner February 20, 2026 11:35
Copilot AI review requested due to automatic review settings February 20, 2026 11:35
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 89.74359% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 74%. Comparing base (6ca9555) to head (7e815e6).
⚠️ Report is 1 commits behind head on develop.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with _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

@Borda
Copy link
Member

Borda commented Feb 20, 2026

@copilot apply changes based on the comments in this thread

Copy link
Contributor Author

Copilot AI commented Feb 20, 2026

@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 _get_logger docstring and tests/utils/test_logger.py was created with 11 tests covering default/custom name, level, LOG_LEVEL env var, stdout/stderr handler wiring, propagate=False, and idempotency.

@Borda Borda merged commit c2dedba into develop Feb 20, 2026
28 checks passed
@Borda Borda deleted the copilot/implement-logging-system branch February 20, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants