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
- A-09 (MEDIUM): 24
print() calls used for diagnostic output — not capturable by log aggregation, no severity levels, no timestamps
- 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
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
Work Stream WS-19: Backend Logging Migration
src/dataviewer/backend/(all.pyfiles)Description
Replace 24
print()calls across backend modules withlogging.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
print()calls used for diagnostic output — not capturable by log aggregation, no severity levels, no timestampsFindings Addressed
print()calls used as diagnostic outputAcceptance Criteria
print()statements insrc/dataviewer/backend/production code (test code excluded)logger = logging.getLogger(__name__)at module levelDEBUGfor detailed diagnostic informationINFOfor normal operational messages (startup, request handling, config loading)WARNINGfor recoverable issues or degraded operationERRORfor failures that need attentionprintfound) enabled forsrc/dataviewer/backend/and passingImplementation Notes
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)logging.config.dictConfig()that matches uvicorn's formatters%sstyle formatting in log calls (not f-strings) to allow lazy evaluationpyproject.tomlfor the dataviewer backend pathRelated Issues
Migrated from Azure-Samples/azure-nvidia-robotics-reference-architecture#400