Conversation
aa31fe2 to
5929e59
Compare
|
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! |
5929e59 to
520e074
Compare
|
bumping this — still interested in getting it merged if it looks good to you |
|
checking in - is there anything else needed? |
|
hey sorry, for the delays. there're currently three things:
If you want to keep this mergeable: fix the history and don't ever import anything in test functions. I don't know why Claude loves doing that so much. |
|
Hey, totally understand on all three points — no rush at all, get attrs out first! Re: the commit history, yeah that's on me — I was experimenting with some tooling and didn't clean it up before pushing. I'll rebase and squash to fix that. And I hear you on point 3. If you're thinking about a broader rework of how processors get execution context, this small patch might not be the right approach. Happy to close this if you'd rather tackle it as part of that larger redesign. Just let me know which way you want to go. |
|
Done! Squashed into a single commit with a clean history — no more co-author tags. Also moved the BytesLogger imports in test_stdlib.py to the top-level import block instead of inside the test functions. Totally understand on point 3 about the broader design direction. If you'd rather tackle the name attribute as part of a larger processor context rework, I'm happy to close this and let you drive that. Otherwise it's ready to go whenever you are. |
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
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