Skip to content

fix: scope logging handler to haystack logger, not root#11567

Closed
sanjuchand wants to merge 1 commit into
deepset-ai:mainfrom
sanjuchand:fix/dont-hijack-root-logger
Closed

fix: scope logging handler to haystack logger, not root#11567
sanjuchand wants to merge 1 commit into
deepset-ai:mainfrom
sanjuchand:fix/dont-hijack-root-logger

Conversation

@sanjuchand

Copy link
Copy Markdown

Summary

Fixes #8681.

configure_logging() was adding its StreamHandler to the root logger, which violates Python's logging best practices for libraries and silently breaks any application that calls logging.basicConfig() after importing Haystack — basicConfig is documented as a no-op once any handlers are already registered on the root logger.

Change: Scope the HaystackLoggingHandler to logging.getLogger("haystack") instead of logging.getLogger() (root). This means the structured formatter applies to all haystack.* loggers as before, but no longer pollutes the root logger.

Test plan

  • Updated reset_logging_config fixture to reset haystack logger handlers (not root)
  • Updated all test loggers to use haystack.test namespace so they route through the scoped handler
  • Added TestRootLoggerNotModified with two new tests:
    • test_configure_logging_does_not_add_handler_to_root_logger — regression test for the exact bug
    • test_configure_logging_adds_handler_to_haystack_logger — confirms the handler lands in the right place
  • Release note included

🤖 Generated with Claude Code

configure_logging() was adding its StreamHandler to the root logger,
which silently breaks any application that calls logging.basicConfig()
after importing Haystack (basicConfig is a no-op once handlers exist).

Scope the handler to logging.getLogger("haystack") instead, following
the Python logging docs' guidance that libraries must not configure
root logger handlers.

Fixes deepset-ai#8681

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sanjuchand sanjuchand requested a review from a team as a code owner June 10, 2026 00:39
@sanjuchand sanjuchand requested review from anakin87 and removed request for a team June 10, 2026 00:39
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

@sanjuchand is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sanjuchand

Copy link
Copy Markdown
Author

Closing as a duplicate of #11553, which covers the same fix and was opened earlier today. Good luck with the merge!

@sanjuchand sanjuchand closed this Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Haystack should not configure root logger handlers

2 participants