Skip to content

Conversation

@jkebinger
Copy link
Collaborator

Summary

This PR fixes the InternalLogger class to properly register with Python's logging hierarchy, enabling handler propagation from logging.basicConfig() and parent loggers.

Problem

InternalLogger instances were not being registered with Python's logging manager, causing:

  • No parent logger assignment (parent = None)
  • No handler propagation from logging.basicConfig() or parent loggers
  • SDK internal logs invisible without manual configuration

Changes

1. Logger Hierarchy Registration (_internal_logging.py)

  • Register each InternalLogger with logging.Logger.manager.loggerDict during __init__
  • Establish proper parent-child relationships in the logging hierarchy (adapted from Python's _fixupParents)
  • Enable handler inheritance from parent loggers

2. Fix prefab_internal Attribute

  • Changed from overriding log() to _log() method
  • The info(), debug(), etc. methods call _log() directly, not log()
  • Properly injects prefab_internal=True into all log records
  • Safely handles the extra parameter as a dictionary

3. Version Bump

  • Bumped version from 1.1.0 to 1.1.1
  • Updated CHANGELOG.md with fix description

Testing

✅ All 364 tests pass
✅ Pre-commit hooks pass (black, ruff, prettier, mypy)
✅ Manual testing confirms logger hierarchy works correctly
✅ Logger inherits handlers from root and parent loggers
prefab_internal attribute is properly set on all log records

Ported From

This fix was originally implemented in the prefab-cloud-python repository:
prefab-cloud/prefab-cloud-python#127

🤖 Generated with Claude Code

jkebinger and others added 2 commits November 20, 2025 10:33
InternalLogger instances were not being registered with Python's logging
manager, causing them to have no parent logger and preventing handler
propagation. This meant that:
- basicConfig() had no effect on InternalLogger instances
- They couldn't inherit handlers from parent loggers
- Users couldn't see SDK internal logs without manual configuration

This commit fixes the issue by:

1. Registering InternalLogger instances with logging.Logger.manager.loggerDict
   during __init__, ensuring they participate in the logging hierarchy

2. Setting up parent loggers properly (adapted from Python's logging
   internals) so handlers propagate correctly

3. Fixing the prefab_internal extra attribute by overriding _log() instead
   of log(), since info(), debug(), etc. call _log() directly

The fix is compatible with both:
- Standard logging (logging.basicConfig, manual handler configuration)
- Structlog (when configured to use stdlib logging)

The prefab_internal=True extra attribute is still added to all log records
from InternalLogger instances, allowing users to filter/identify SDK
internal messages.

Ported from: prefab-cloud/prefab-cloud-python#127

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@jdwyah jdwyah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@jkebinger jkebinger merged commit 245b9f2 into main Nov 20, 2025
7 checks passed
@jkebinger jkebinger deleted the port-logger-fixes branch November 20, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants