Repository navigation
fix(logging): resolve qualified method name dynamically in method_logger - #4082
Conversation
- Replace static inspect.getouterframes() lookup at decorator definition time with dynamic func.__qualname__ evaluation inside the wrapper. - Prevent '<module>' or outer frame names from being logged when decorating class methods. - Add unit test in tests/test_mesa_logging.py verifying qualified class and method name logging.
|
Thanks for adding a focused logging test, @priyanshux-dev. Running the #4069 reproducer against current source logs Could you update #4069 with the model or debugging workflow where the current name causes a problem, including a minimal example and its actual output? That will clarify which failure this PR should address. Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot. |
|
Thanks for the note! I've updated #4069 with a minimal reproducer showing where static frame inspection (
Replacing frame inspection with |
…ger (#4082) * fix(logging): resolve qualified method name dynamically in method_logger - Replace static inspect.getouterframes() lookup at decorator definition time with dynamic func.__qualname__ evaluation inside the wrapper. - Prevent '<module>' or outer frame names from being logged when decorating class methods. - Add unit test in tests/test_mesa_logging.py verifying qualified class and method name logging. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * style(tests) : move method_logger import to top of file. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit 86a34d8)
Pre-PR Checklist
Summary
Resolve the qualified class and method name dynamically via
func.__qualname__insidemethod_logger()instead of static definition-time stack inspection.Bug / Issue
Fixes #4069.
method_logger()inmesa/mesa_logging.pypreviously evaluatedinspect.getouterframes(inspect.currentframe())[1][3]at decorator definition time. Because class bodies execute before the class object is constructed, this captured<module>(or an outer enclosing frame name) rather than the actual class name, and was fragile under nested scopes or composed decorators.Implementation
inspect.getouterframes()lookup inmethod_logger()(mesa/mesa_logging.py) with dynamicfunc.__qualname__evaluation inside the wrapper function, preserving the existingargs[1::]andkwargslog format.test_method_logger_logs_qualname) intests/test_mesa_logging.pyverifying that decorated class methods log their qualified class and method name without altering return values.Testing
test_method_logger_logs_qualnamefails on unmodifiedmain(logging<module>.step) and passes with this fix.pytest tests/test_mesa_logging.pypassed locally.Additional Notes
This change is strictly scoped to
method_logger()formatting and does not altercreate_module_logger(),function_logger(), or any logger handler/level configuration.