Skip to content

fix(logging): corrects InterceptHandler frame walker off-by-one#587

Open
vivekkeshore wants to merge 1 commit into
coderamp-labs:mainfrom
vivekkeshore:bug-586
Open

fix(logging): corrects InterceptHandler frame walker off-by-one#587
vivekkeshore wants to merge 1 commit into
coderamp-labs:mainfrom
vivekkeshore:bug-586

Conversation

@vivekkeshore

@vivekkeshore vivekkeshore commented Jun 17, 2026

Copy link
Copy Markdown

What: walk from currentframe().f_back with depth=1, not
currentframe() with depth=2.

Why: currentframe() returns emit's own frame, so the guard
against logging.__file__ was False on the first check — the
loop never ran and intercepted records were attributed to stdlib
Logger.callHandlers instead of the actual originating caller.

How: .f_back skips emit so the guard matches stdlib frames and
the walk advances; depth=1 compensates for the skipped frame.

Added positive and negative regression tests.

Fixes #586

  What: walk from `currentframe().f_back` with `depth=1`, not
  `currentframe()` with `depth=2`.

  Why: `currentframe()` returns emit's own frame, so the guard
  against `logging.__file__` was False on the first check — the
  loop never ran and intercepted records were attributed to stdlib
  `Logger.callHandlers` instead of the actual originating caller.

  How: `.f_back` skips emit so the guard matches stdlib frames and
  the walk advances; `depth=1` compensates for the skipped frame.

  Added positive and negative regression tests.
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.

(bug): InterceptHandler corrupts call-site attribution for every stdlib-logging library.

1 participant