fix: scope logging configuration to the haystack logger instead of root#11553
Open
eldar702 wants to merge 1 commit into
Open
fix: scope logging configuration to the haystack logger instead of root#11553eldar702 wants to merge 1 commit into
eldar702 wants to merge 1 commit into
Conversation
…ot (deepset-ai#8681) `configure_logging()` attached its handler to the root logger and wholesale-replaced `root_logger.handlers`, which hijacked the host application's logging configuration and silently overrode a downstream `logging.basicConfig()` call. Scope the handler to the `haystack` logger hierarchy instead, following the Python logging best practice that libraries should not modify the root logger. Mirrors the approach of the previously maintainer-reviewed PR deepset-ai#10763. Existing handler-dependent tests were updated to emit through the `haystack` logger, and the test reset fixture now also restores the `haystack` logger's handlers to keep test isolation. Fixes deepset-ai#8681 AI-assisted contribution.
|
@eldar702 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
4 tasks
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.
Summary
Importing Haystack mutates the root logger's handlers, so any application-level logging configuration (e.g. a downstream
logging.basicConfig()) is silently overridden. This scopes Haystack's logging handler to thehaystacklogger hierarchy instead.This revives the approach of #10763 — which a maintainer reviewed and approved, and which was closed only for inactivity after the original author never signed the CLA — rather than a new design.
Root cause
haystack/logging.py::configure_logging():root_logger = logging.getLogger()(the root logger)root_logger.handlers = new_handlers(wholesale replacement of the host app's root handlers)Fix
logging.getLogger("haystack")instead of root, so the host application's root configuration is preserved.haystack/logging.py+6/-3.Testing
configure_logging(), a laterlogging.basicConfig()is respected, the root logger carries noHaystackLoggingHandler, and ahaystack.*logger does.haystack.*logger hierarchy (required now that the handler is scoped there) and updated the autouse fixture to also reset thehaystacklogger.hatch run test:unit test/test_logging.py→ 47/47 pass; ruff + reno lint clean.releasenotes/notes/scope-logging-to-haystack-logger-8b544e319b11b368.yaml.fixes #8681
Drafted with AI assistance (Claude Opus); reviewed and tested. The deepset CLA will be signed by me (the human contributor) when the cla-assistant bot prompts.