Skip to content

logging: also capture logs from non-propagating loggers#14375

Open
bluetech wants to merge 2 commits intopytest-dev:mainfrom
bluetech:logging-propagation
Open

logging: also capture logs from non-propagating loggers#14375
bluetech wants to merge 2 commits intopytest-dev:mainfrom
bluetech:logging-propagation

Conversation

@bluetech
Copy link
Copy Markdown
Member

Previously, we only attached our capturing handler to the root logger. This means that logs emitted by non-propagating loggers (including all children which propagate to them) were not captured.

As far as I can see, for the pytest use case, we do always want to capture these logs, for both test reporting (i.e. the "Captured log calls" section) and caplog testing.

Fix by attaching to all non-propagating loggers in addition to the root logger. This approach doesn't handle loggers which become non-propagating during the test, which seems OK to me.

A downside is that the (somewhat performance-sensitive) per-test logging setup becomes a bit slower (depending on the logging setup).

Fix #3697

Tobias Deiminger and others added 2 commits April 10, 2026 11:39
…f non-propagating loggers

Demonstrate the bug/missing functionality of reporting logs emitted by
non-propagating loggers (i.e. loggers which don't reach the root logger,
where we currently attach our handler).

Refs pytest-dev#3697

[ran: extracted from pytest-dev#10303 and changed to use HookRecorder]
Previously, we only attached our capturing handler to the root logger.
This means that logs emitted by non-propagating loggers (including all
children which propagate to *them*) were not captured.

As far as I can see, for the pytest use case, we do always want to
capture these logs, for both test reporting (i.e. the "Captured log
calls" section) and `caplog` testing.

Fix by attaching to all non-propagating loggers in addition to the root
logger. This approach doesn't handle loggers which become
non-propagating during the test, which seems OK to me.

A downside is that the (somewhat performance-sensitive) per-test logging
setup becomes a bit slower (depending on the logging setup).

Fix pytest-dev#3697
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handling of loggers with propagate=False

1 participant