Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions haystack/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,15 @@ def configure_logging(use_json: bool | None = None) -> None:
# Use OUR `ProcessorFormatter` to format all `logging` entries.
handler.setFormatter(formatter)

root_logger = logging.getLogger()
# Scope the handler to the `haystack` logger hierarchy instead of the root logger so that we do not
# hijack the host application's logging configuration (e.g. a downstream `logging.basicConfig()` call).
# See https://github.com/deepset-ai/haystack/issues/8681.
haystack_logger = logging.getLogger("haystack")
# avoid adding our handler twice
old_handlers = [
h
for h in root_logger.handlers
for h in haystack_logger.handlers
if not (isinstance(h, logging.StreamHandler) and h.name == "HaystackLoggingHandler")
]
new_handlers = [handler, *old_handlers]
root_logger.handlers = new_handlers
haystack_logger.handlers = new_handlers
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
`configure_logging()` no longer attaches its handler to (and replaces the handlers of) the root logger.
The Haystack logging handler is now scoped to the `haystack` logger hierarchy, so importing Haystack no
longer hijacks the host application's logging configuration. A downstream `logging.basicConfig()` call is
now respected instead of being silently overridden.
Loading