Skip to content

feat: add structured logging and DEBUG flag - #11

Merged
IceCodeNew merged 3 commits into
masterfrom
feat/add-logging
Jul 13, 2026
Merged

feat: add structured logging and DEBUG flag#11
IceCodeNew merged 3 commits into
masterfrom
feat/add-logging

Conversation

@IceCodeNew

@IceCodeNew IceCodeNew commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Add structured lifecycle logging with useful INFO output by default and opt-in DEBUG diagnostics.

Changes

Logging configuration

  • Add Settings.debug, controlled by DEBUG=1, true, or yes
  • Configure one idempotent stderr handler at INFO before runtime settings are parsed, with explicit datefmt removing milliseconds
  • Configure root logger handler for third-party logs (e.g., APScheduler)
  • Update the level after configuration loads and disable propagation to avoid duplicate root output
  • Document the flag in env.example, the README, and the design contract

Lifecycle logging

  • Log daemon and briefing startup, configured location count, and per-location processing
  • Log RSS feed and article counts
  • Log publish and skip outcomes
  • Report stale RSS sources at WARNING
  • Include timestamps, levels, and logger names in every application log line

Failure handling

  • Preserve consecutive failure counts as exception context
  • Emit a full traceback once at the process boundary
  • Let APScheduler own scheduled-job tracebacks (via root logger handler)
  • Exit one-shot CLI failures with status 1 without printing a second interpreter traceback

Debug diagnostics

When DEBUG=true, additionally log:

  • RSS fetch details
  • New and historical article counts
  • Active warning and context counts
  • LLM attempt numbers, validation failures, and success-on-attempt

Usage

# INFO lifecycle logs
weather-briefing run hourly

# Verbose diagnostics
DEBUG=true weather-briefing run hourly

Review fixes

  • Added explicit datefmt="%Y-%m-%d %H:%M:%S" to log formatter to avoid milliseconds
  • Configured root logger handler idempotently for third-party library log output
  • Moved LLM success log into _summarize to include actual attempt count
  • Added test coverage for daemon-branch exception handling in main()

Summary by CodeRabbit

  • New Features

    • Added configurable application logging to standard error.
    • Added DEBUG=true support for detailed diagnostics, including RSS and LLM processing.
    • Added clearer runtime messages for scheduling, location processing, publishing, skipped runs, and failures.
  • Bug Fixes

    • Improved CLI error handling to report failures consistently and exit with an error status.
    • Added failure context showing consecutive briefing failures.
    • Improved warnings for stale sources and empty results.

@IceCodeNew
IceCodeNew force-pushed the test/improve-coverage branch from d23155a to 6b7bf0d Compare July 13, 2026 19:25
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.95082% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.60%. Comparing base (04b8017) to head (7d45621).

Files with missing lines Patch % Lines
weather_briefing/cli.py 87.17% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
+ Coverage   93.65%   94.60%   +0.94%     
==========================================
  Files          34       34              
  Lines        2933     3170     +237     
  Branches      198      201       +3     
==========================================
+ Hits         2747     2999     +252     
+ Misses        140      123      -17     
- Partials       46       48       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@IceCodeNew
IceCodeNew force-pushed the test/improve-coverage branch from 6b7bf0d to 52e7212 Compare July 13, 2026 19:33
Base automatically changed from test/improve-coverage to master July 13, 2026 19:35
@IceCodeNew
IceCodeNew force-pushed the feat/add-logging branch 2 times, most recently from ca6dbe2 to 0e6bae7 Compare July 13, 2026 19:48
@IceCodeNew
IceCodeNew requested a review from Copilot July 13, 2026 19:48

Copilot AI left a comment

Copy link
Copy Markdown

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 introduces structured, opt-in debug logging across the CLI entrypoints and the briefing service, controlled by a new Settings.debug flag derived from the DEBUG environment variable. The goal is to make runs observable (start/end, per-location actions, RSS/LLM diagnostics) while keeping default output concise.

Changes:

  • Add debug: bool to Settings and parse DEBUG env var truthy values.
  • Add CLI logging initialization and replace user-facing print output with structured logs + top-level exception logging.
  • Add service-level logs for RSS fetches, staleness warnings, skip reasons, and LLM retry/validation diagnostics.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
weather_briefing/service.py Adds structured service logs around RSS ingestion, skip conditions, and LLM retry/validation flow.
weather_briefing/config.py Adds Settings.debug sourced from DEBUG env var.
weather_briefing/cli.py Adds logging configuration, run lifecycle logs, and top-level exception logging.
tests/test_service.py Asserts consecutive-failure context is attached to raised exceptions via __notes__.
tests/test_config.py Adds coverage for DEBUG truthy parsing (including quoted values).
tests/test_cli.py Adds coverage for idempotent logging configuration and main() error logging.
README.md Documents stderr logging and DEBUG=true diagnostics behavior.
env.example Documents the DEBUG environment variable.
docs/design.md Documents the intended logging behavior and rationale.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread weather_briefing/cli.py
Comment thread weather_briefing/service.py
- Add  setup with configurable DEBUG level via  env var
- Log briefing lifecycle: run start, location processing, article counts,
  stale source warnings, publish results
- Log LLM retry attempts at DEBUG level
- Log full tracebacks on errors via
- All messages go to stderr with timestamps and level prefixes

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread tests/test_cli.py
Comment thread tests/test_cli.py
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@IceCodeNew, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 97788357-3588-4ce2-95f8-a55df645d662

📥 Commits

Reviewing files that changed from the base of the PR and between a5cb78a and 7d45621.

📒 Files selected for processing (9)
  • README.md
  • docs/design.md
  • env.example
  • tests/test_cli.py
  • tests/test_config.py
  • tests/test_service.py
  • weather_briefing/cli.py
  • weather_briefing/config.py
  • weather_briefing/service.py
📝 Walkthrough

Walkthrough

新增 DEBUG 配置及 stderr 日志说明;CLI 统一配置日志、记录运行进度并处理未捕获异常;BriefingService 增加 RSS、发布、LLM 重试和连续失败诊断日志,测试覆盖相关行为。

Changes

Structured logging and diagnostics

Layer / File(s) Summary
Logging configuration contract
weather_briefing/config.py, README.md, docs/design.md, env.example, tests/test_config.py
Settings 新增 debug 字段并解析多种 truthy 值;文档和示例补充 DEBUG、stderr 及异常记录规则。
CLI logging and execution flow
weather_briefing/cli.py, tests/test_cli.py
CLI 以幂等方式配置 stderr handler,记录运行、调度、地点和发布状态,并将未捕获异常记录后以状态码 1 退出;新增对应测试。
Briefing service diagnostics
weather_briefing/service.py, tests/test_service.py
服务增加 RSS、陈旧来源、空结果、小时跳过和 LLM 重试日志,并为异常附加连续失败次数;测试验证异常备注。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as weather_briefing.cli
  participant Settings as Settings.from_env
  participant Service as BriefingService
  participant stderr
  CLI->>Settings: 读取 DEBUG 配置
  CLI->>CLI: 配置 stderr logging
  CLI->>Service: 执行 briefing run
  Service-->>CLI: 返回发布内容或 None
  Service->>stderr: 输出 RSS、LLM 与失败诊断
  CLI->>stderr: 输出运行状态或未捕获异常
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: structured logging plus a new DEBUG flag.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-logging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_cli.py`:
- Around line 327-336: Fix the eagerly evaluated self-referencing return
annotations in _FakeAsyncClient.__aenter__ and FakeState.__enter__ by quoting
each class name as a forward reference. Preserve the existing context-manager
behavior and signatures otherwise so the test module imports successfully.
- Line 387: Rename the unused lambda parameter in the monkeypatch for
httpx.AsyncClient to a descriptive, non-ambiguous name, while preserving the
existing _FakeAsyncClient construction and behavior.

In `@weather_briefing/cli.py`:
- Around line 82-98: The _configure_logging function currently enables DEBUG on
the root logger, exposing verbose httpx/httpcore request metadata. Keep
application debug logging while explicitly pinning the httpx and httpcore logger
levels to a safer threshold, or apply equivalent redaction before setting
logging.root to DEBUG; ensure API keys, bearer tokens, and URLs cannot be
emitted to stderr.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d0f07df-fd83-427f-b660-7660c0210831

📥 Commits

Reviewing files that changed from the base of the PR and between 04b8017 and a5cb78a.

📒 Files selected for processing (9)
  • README.md
  • docs/design.md
  • env.example
  • tests/test_cli.py
  • tests/test_config.py
  • tests/test_service.py
  • weather_briefing/cli.py
  • weather_briefing/config.py
  • weather_briefing/service.py

Comment thread tests/test_cli.py
Comment thread tests/test_cli.py
Comment thread weather_briefing/cli.py
@IceCodeNew
IceCodeNew merged commit 76c20c9 into master Jul 13, 2026
21 checks passed
@IceCodeNew
IceCodeNew deleted the feat/add-logging branch July 13, 2026 21:08
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.

2 participants