-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
gh-132372: Speed up logging.config existing logger handling #150242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vsajip
merged 4 commits into
python:main
from
esadomer:codex/find-stronger-cpython-speedup
May 29, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
55a64e2
gh-132372: Speed up logging.config existing logger handling
esadomer 4040d60
gh-132372: Batch logging cache clearing
esadomer d076b07
gh-132372: Address logging config review comments
esadomer 843bd2e
gh-132372: Use Logger.setLevel for preserved children
esadomer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-132372: Batch logging cache clearing
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
- Loading branch information
commit 4040d60321b083c7645c357313a0c2be8f3fa561
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -188,15 +188,20 @@ def _handle_existing_loggers(existing, child_loggers, disable_existing): | |||||
| disabled if disable_existing is false. | ||||||
| """ | ||||||
| root = logging.root | ||||||
| cache_clear_needed = False | ||||||
| for log in existing: | ||||||
| logger = root.manager.loggerDict[log] | ||||||
| if log in child_loggers: | ||||||
| if not isinstance(logger, logging.PlaceHolder): | ||||||
| logger.setLevel(logging.NOTSET) | ||||||
| # Equivalent to setLevel(NOTSET), but clear the cache once. | ||||||
| logger.level = logging.NOTSET | ||||||
| logger.handlers = [] | ||||||
| logger.propagate = True | ||||||
| cache_clear_needed = True | ||||||
| else: | ||||||
| logger.disabled = disable_existing | ||||||
| if cache_clear_needed: | ||||||
| root.manager._clear_cache() | ||||||
|
|
||||||
| def _discard_existing_logger(name, existing, existing_set, child_loggers): | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Maybe something like that instead (since we also update child_loggers) |
||||||
| """Discard a configured logger and record its existing children.""" | ||||||
|
|
||||||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change really necessary? while
setLevelwould clear the cache multiple times, I would prefer that we pass throughlogger.setLevelpublic API instead of changing.leveldirectly, just in case someone has a logger subclass that does something else withsetLevel.