Skip to content

refactor(dataviewer): migrate 24 print() calls to structured logging with uvicorn integration #131

Description

Work Stream WS-19: Backend Logging Migration

Attribute Value
FR ID FR-WS-19
Priority P3
Tier 3 — Cleanup & Polish
Depends On WS-05 (#118), WS-06 (needs dedicated issue), WS-07 (#119), WS-08 (#120), WS-13 (#125)
File Zone src/dataviewer/backend/ (all .py files)
Effort Medium
Tracking Issue #115

Description

Replace 24 print() calls across backend modules with logging.getLogger(__name__) and configure structured logging with uvicorn integration. Ensure all modules use appropriate log levels (DEBUG, INFO, WARNING, ERROR) based on the nature of the output.

Issues addressed

  1. A-09 (MEDIUM): 24 print() calls used for diagnostic output — not capturable by log aggregation, no severity levels, no timestamps
  2. A-11 (LOW): No structured logging configuration — when logging is used, it lacks consistent format and uvicorn integration

Findings Addressed

Finding Severity Summary
A-09 MEDIUM 24 print() calls used as diagnostic output
A-11 LOW No structured logging configuration or uvicorn integration

Acceptance Criteria

  • Zero print() statements in src/dataviewer/backend/ production code (test code excluded)
  • Every backend module uses logger = logging.getLogger(__name__) at module level
  • Log calls use appropriate severity levels:
    • DEBUG for detailed diagnostic information
    • INFO for normal operational messages (startup, request handling, config loading)
    • WARNING for recoverable issues or degraded operation
    • ERROR for failures that need attention
  • Logging configuration integrates with uvicorn's log format and handlers (no duplicate output)
  • Log format includes: timestamp, level, logger name, and message at minimum
  • Ruff rule T201 (print found) enabled for src/dataviewer/backend/ and passing

Implementation Notes

  • Module-level logger pattern:
    import logging
    
    logger = logging.getLogger(__name__)
  • Mapping print() to logging:
    • print(f"Loading config...") → logger.info("Loading config from %s", path)
    • print(f"Error: {e}") → logger.error("Failed to process: %s", e)
    • print(f"DEBUG: {value}") → logger.debug("Value: %s", value)
  • Uvicorn integration: configure in the FastAPI app startup or via logging.config.dictConfig() that matches uvicorn's formatters
  • Use %s style formatting in log calls (not f-strings) to allow lazy evaluation
  • Enable Ruff rule T201 in pyproject.toml for the dataviewer backend path

Related Issues


Migrated from Azure-Samples/azure-nvidia-robotics-reference-architecture#400

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/srcSource code in src directorypriority-3Medium: Standard priorityrefactorCode restructuring without behavior changesize-mMedium: 4-8 hours

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions