Fix caplog by enabling log propagation in app logger#311
Merged
marcgibbons merged 2 commits intomainfrom Mar 8, 2026
Merged
Conversation
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
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #102
The
PROJECT_NAMElogger hadpropagate=Falseand its ownconsolehandler to avoid double-logging to the root logger. This also prevented pytest'scaplogfixture from capturing app logs, sincecaplogworks by intercepting records at the root logger level.Fix: remove the redundant
consolehandler from the app logger and setpropagate=True. Log records now flow up to the root logger (which owns theconsolehandler), so they reach it exactly once andcaplogcan capture them as expected.The
PROJECT_NAMElogger entry is still needed to setLOG_LEVEL(defaultINFO) independently from the root logger'sWARNINGlevel.Tests added:
INFOnot captured,WARNINGcapturedINFOcaptured,WARNINGcaptured