Repository navigation
fix(logging): stop knowledge_mapper log records being emitted twice - #74
Merged
Merged
Conversation
The knowledge_mapper logger attaches its own handler on import but did not disable propagation. If the host application also configures the root logger (e.g. via logging.basicConfig()), every record from knowledge_mapper (and its child loggers) was handled once by the library's own handler and again when it propagated up to the root logger's handler, producing duplicate log lines in differing formats. Set propagate = False on the knowledge_mapper logger so records are only emitted via its own handler. Document this behavior in CONTEXT.md, including how host applications can opt out. Fixes #72 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Closes #72.
knowledge_mapper's package__init__.pyattaches its ownStreamHandler(with its own formatter) to theknowledge_mapperlogger so output looks reasonable without any setup by the host application. It did not, however, setpropagate = False.When a host application also configures the root logger (e.g. via
logging.basicConfig(), as seen in the reported KB scripts), every record emitted by aknowledge_mapper.*logger was handled twice:knowledge_mapper's own handler/formatter.Fix
Set
propagate = Falseon theknowledge_mapperlogger, so records handled by its own handler stop there and are not forwarded to ancestor loggers (e.g. root). No other behavior changes.Documented the behavior (and how to opt out, for host apps that want full control) in
CONTEXT.md.Testing
Added
tests/test_logging.py:propagateisFalseon the package logger.knowledge_mapper.*child logger, and asserts the host's root handler never receives the record (i.e. no duplicate emission).Full test suite and
ruff check/ruff format --checkpass.