Skip to content

fix(logging): stop knowledge_mapper log records being emitted twice - #74

Merged
david-debest merged 1 commit into
mainfrom
72-fix/duplicate-log-statements
Oct 19, 2026
Merged

david-debest merged 1 commit into
mainfrom
72-fix/duplicate-log-statements

Conversation

@david-debest

Copy link
Copy Markdown
Contributor

Summary

Closes #72.

knowledge_mapper's package __init__.py attaches its own StreamHandler (with its own formatter) to the knowledge_mapper logger so output looks reasonable without any setup by the host application. It did not, however, set propagate = 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 a knowledge_mapper.* logger was handled twice:

  1. Once by knowledge_mapper's own handler/formatter.
  2. Once more after bubbling up to the root logger's handler (with a different, host-configured format) — this is exactly what's shown in the issue's log excerpt, where each line appears twice in two different formats.

Fix

Set propagate = False on the knowledge_mapper logger, 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:

  • Asserts propagate is False on the package logger.
  • Simulates a host app that attaches a handler to the root logger, then logs via a 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 --check pass.

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>
@david-debest david-debest self-assigned this Oct 19, 2026
@david-debest
david-debest merged commit d293bf4 into main Oct 19, 2026
3 checks passed
@david-debest
david-debest deleted the 72-fix/duplicate-log-statements branch October 27, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent duplicate statements in logging of knowledge-mapper

1 participant