Skip to content

Fix caplog by enabling log propagation in app logger#311

Merged
marcgibbons merged 2 commits intomainfrom
102-caplog
Mar 8, 2026
Merged

Fix caplog by enabling log propagation in app logger#311
marcgibbons merged 2 commits intomainfrom
102-caplog

Conversation

@marcgibbons
Copy link
Contributor

Closes #102

The PROJECT_NAME logger had propagate=False and its own console handler to avoid double-logging to the root logger. This also prevented pytest's caplog fixture from capturing app logs, since caplog works by intercepting records at the root logger level.

Fix: remove the redundant console handler from the app logger and set propagate=True. Log records now flow up to the root logger (which owns the console handler), so they reach it exactly once and caplog can capture them as expected.

The PROJECT_NAME logger entry is still needed to set LOG_LEVEL (default INFO) independently from the root logger's WARNING level.

Tests added:

  • Root logger: INFO not captured, WARNING captured
  • App logger: INFO captured, WARNING captured

The PROJECT_NAME logger had propagate=False and its own console handler
to avoid double-logging to the root logger. This also prevented pytest's
caplog fixture from capturing app logs, since caplog works by intercepting
records at the root logger level.

The fix: remove the redundant console handler from the app logger and set
propagate=True. Log records now flow up to the root logger (which owns
the console handler), so they reach it exactly once and caplog can capture
them as expected.

The PROJECT_NAME logger entry is still needed to set LOG_LEVEL (default
INFO) independently from the root logger's WARNING level.

Closes #102
@marcgibbons marcgibbons enabled auto-merge (squash) March 8, 2026 17:41
@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (10f5bcd) to head (43d3911).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #311   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        16    +1     
  Lines          324       343   +19     
  Branches         3         3           
=========================================
+ Hits           324       343   +19     

☔ View full report in Codecov by Sentry.
📢 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.

@marcgibbons marcgibbons merged commit 1163f27 into main Mar 8, 2026
5 checks passed
@marcgibbons marcgibbons deleted the 102-caplog branch March 8, 2026 17:44
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.

Ensure caplog works in test suite

1 participant