Open
Conversation
BytesLogger lacked a `name` attribute, causing `add_logger_name` to raise AttributeError when used with BytesLoggerFactory. The first positional argument passed to BytesLoggerFactory (the logger name from `get_logger()`) is now forwarded to BytesLogger as its `name` attribute. Closes hynek#734 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
for more information, see https://pre-commit.ci
aa31fe2 to
5929e59
Compare
Author
|
Hi @hynek, friendly ping on this PR. It's been open for about 10 days now without any review activity. Would appreciate any feedback when you have a moment -- happy to adjust if anything needs changing. Thank you! |
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
AttributeError: 'BytesLogger' object has no attribute 'name'when usingadd_logger_nameprocessor withBytesLoggerFactory(closes AttributeError: 'BytesLogger' object has no attribute 'name' #734)nameslot toBytesLoggerand accepts it as a keyword-only argument in__init__BytesLoggerFactory.__call__to forward the first positional argument (the logger name fromget_logger()) toBytesLoggerDetails
As reported in #734, using
structlog.stdlib.add_logger_namewithBytesLoggerFactorycrashes becauseBytesLoggerhas nonameattribute. Theadd_logger_nameprocessor accesseslogger.namewhen no_recordis present in the event dict.This implements the fix suggested by @hynek in #734 (comment) with one additional safety guard:
BytesLoggerFactory.__call__usesargs[0] if args else Noneto avoid anIndexErrorwhen no positional arguments are passed to the factory.Test plan
TestBytesLogger::test_name_attribute-- verifies BytesLogger accepts a name kwargTestBytesLogger::test_name_defaults_to_none-- verifies default is NoneTestBytesLoggerFactory::test_passes_name_from_args-- verifies factory forwards nameTestBytesLoggerFactory::test_name_defaults_to_none-- verifies no-arg caseTestBytesLoggerFactory::test_extra_args_ignored-- verifies extra args beyond first are ignoredTestAddLoggerName::test_logger_name_added_with_bytes_logger-- end-to-end test with named BytesLoggerTestAddLoggerName::test_logger_name_none_with_unnamed_bytes_logger-- end-to-end test with unnamed BytesLogger