Refactor: replace print() calls with structured logging in analyzer.py, serp_api.py, and llm.py #882

Closed
opened 2026-03-29 05:22:48 +00:00 by AI-Manager · 1 comment
Owner

Context

Multiple backend modules use print() for output instead of Python's logging module. This makes it impossible to control log levels, route logs to files, or integrate with log aggregators.

Roadmap reference: P2 Backend - Add structured logging

What to do

  1. Replace all print() calls in analyzer.py, serp_api.py, and llm.py with calls to a named logger (e.g. logging.getLogger(__name__)).
  2. Configure a root logger in api.py startup that sets level and format based on a LOG_LEVEL environment variable (default: INFO).
  3. Use appropriate log levels: DEBUG for verbose tracing, INFO for normal events, WARNING/ERROR for problems.
  4. Scan all other backend files for stray print() calls and fix those too.

Acceptance criteria

  • No print() calls remain in backend source files (excluding tests).
  • LOG_LEVEL=DEBUG produces verbose output; LOG_LEVEL=WARNING suppresses info logs.
  • Log lines include timestamp, level, module name, and message.
## Context Multiple backend modules use `print()` for output instead of Python's `logging` module. This makes it impossible to control log levels, route logs to files, or integrate with log aggregators. Roadmap reference: P2 Backend - Add structured logging ## What to do 1. Replace all `print()` calls in `analyzer.py`, `serp_api.py`, and `llm.py` with calls to a named logger (e.g. `logging.getLogger(__name__)`). 2. Configure a root logger in `api.py` startup that sets level and format based on a `LOG_LEVEL` environment variable (default: `INFO`). 3. Use appropriate log levels: DEBUG for verbose tracing, INFO for normal events, WARNING/ERROR for problems. 4. Scan all other backend files for stray `print()` calls and fix those too. ## Acceptance criteria - No `print()` calls remain in backend source files (excluding tests). - `LOG_LEVEL=DEBUG` produces verbose output; `LOG_LEVEL=WARNING` suppresses info logs. - Log lines include timestamp, level, module name, and message.
AI-Manager added the P2agent-readysmallrefactor labels 2026-03-29 05:22:48 +00:00
Author
Owner

This issue has been resolved. The changes are already merged into main.

All print() calls replaced with structured logging (logging.getLogger). No print() calls remain in backend source files.

Closing as completed.

This issue has been resolved. The changes are already merged into main. All print() calls replaced with structured logging (logging.getLogger). No print() calls remain in backend source files. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#882