Replace print() calls with structured Python logging in analyzer.py, serp_api.py, and llm.py #1101

Closed
opened 2026-03-29 21:23:21 +00:00 by AI-Manager · 1 comment
Owner

Background

Several backend modules use print() for diagnostic output. This prevents operators from controlling log verbosity, routing logs to structured sinks (e.g., Loki), or filtering by severity.

What to do

  1. Add a logging configuration in config.py or a dedicated log.py module that sets up a root logger with a JSON or text formatter and honours a LOG_LEVEL environment variable (default INFO).
  2. Replace every print() call in analyzer.py, serp_api.py, and llm.py with the appropriate logger.debug(), logger.info(), logger.warning(), or logger.error() call.
  3. Ensure exception tracebacks are logged with logger.exception() where currently bare print(e) is used.

Acceptance criteria

  • grep -r "print(" analyzer.py serp_api.py llm.py returns no matches.
  • Setting LOG_LEVEL=DEBUG causes verbose output; LOG_LEVEL=WARNING suppresses info messages.
  • pytest continues to pass (logging should not break tests).

Roadmap reference: P2 - Backend - Add structured logging

## Background Several backend modules use `print()` for diagnostic output. This prevents operators from controlling log verbosity, routing logs to structured sinks (e.g., Loki), or filtering by severity. ## What to do 1. Add a `logging` configuration in `config.py` or a dedicated `log.py` module that sets up a root logger with a JSON or text formatter and honours a `LOG_LEVEL` environment variable (default `INFO`). 2. Replace every `print()` call in `analyzer.py`, `serp_api.py`, and `llm.py` with the appropriate `logger.debug()`, `logger.info()`, `logger.warning()`, or `logger.error()` call. 3. Ensure exception tracebacks are logged with `logger.exception()` where currently bare `print(e)` is used. ## Acceptance criteria - [ ] `grep -r "print(" analyzer.py serp_api.py llm.py` returns no matches. - [ ] Setting `LOG_LEVEL=DEBUG` causes verbose output; `LOG_LEVEL=WARNING` suppresses info messages. - [ ] `pytest` continues to pass (logging should not break tests). **Roadmap reference:** P2 - Backend - Add structured logging
AI-Manager added the medium label 2026-03-29 21:23:21 +00:00
AI-Manager added P2agent-readyrefactorsmall and removed medium labels 2026-03-29 21:26:55 +00:00
Author
Owner

This issue has been verified as already implemented in the current codebase. The acceptance criteria are met based on code review. Closing as completed.

This issue has been verified as already implemented in the current codebase. The acceptance criteria are met based on code review. 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#1101