Skip to content

fix: scope logging configuration to the haystack logger instead of root#11553

Open
eldar702 wants to merge 1 commit into
deepset-ai:mainfrom
eldar702:fix/8681-scope-logging-to-haystack-logger
Open

fix: scope logging configuration to the haystack logger instead of root#11553
eldar702 wants to merge 1 commit into
deepset-ai:mainfrom
eldar702:fix/8681-scope-logging-to-haystack-logger

Conversation

@eldar702

@eldar702 eldar702 commented Jun 9, 2026

Copy link
Copy Markdown

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 the haystack logger 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

  • Attach/replace handlers on logging.getLogger("haystack") instead of root, so the host application's root configuration is preserved.
  • haystack/logging.py +6/-3.

Testing

  • Added a regression test: after configure_logging(), a later logging.basicConfig() is respected, the root logger carries no HaystackLoggingHandler, and a haystack.* logger does.
  • Adjusted the existing logging tests to the haystack.* logger hierarchy (required now that the handler is scoped there) and updated the autouse fixture to also reset the haystack logger.
  • hatch run test:unit test/test_logging.py → 47/47 pass; ruff + reno lint clean.
  • Added reno release note 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.

…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.
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Jun 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@eldar702 eldar702 marked this pull request as ready for review June 10, 2026 06:55
@eldar702 eldar702 requested a review from a team as a code owner June 10, 2026 06:55
@eldar702 eldar702 requested review from sjrl and removed request for a team June 10, 2026 06:55
@sjrl sjrl assigned sjrl and unassigned sjrl Jun 15, 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

3 participants