tractor
tractor copied to clipboard
Log sys testing, starting to get "serious" about it..
Another sloppy summary anyone?
This pull request introduces significant improvements and refactoring to the logging subsystem in tractor.log. The changes focus on enhancing logger naming behavior, improving sub-logger creation, and updating documentation and type annotations for clarity and maintainability. Additionally, new unit tests have been added to verify the correct logger name handling and module introspection. Below are the most important changes:
Logger Naming and Sub-Logger Improvements:
- Refactored
get_logger()to usepkg_name(formerly_root_name) as the primary root logger identifier, deprecating the old parameter and warning users if it is used. The logger now introspects the caller's module whennameis not provided, automatically generating sub-logger names based on the module context. This avoids duplication of the root package name in logger names and ensures sub-loggers are correctly nested and filtered. [1] [2] [3] - Improved sub-logger creation logic to check for and warn about duplicate root package names or module names in the logger hierarchy, and to only create sub-loggers when appropriate.
Type Annotations and Documentation:
- Added or updated type annotations for logging format variables (
LOG_FORMAT,DATE_FORMAT,BOLD_PALETTE) and clarified docstrings throughout the logging module, making the codebase more readable and maintainable. [1] [2] [3] [4] [5] - Updated and expanded documentation in
tractor/log.pyto describe the enhanced logging system, its concurrency features, and usage patterns.
Testing Enhancements:
- Added a new test file
tests/test_log_sys.pywith unit tests to verify that root package names are not duplicated in logger names and that implicit module name detection for sub-loggers works as intended. This includes utilities for dynamically loading modules from file paths for testing purposes.
Internal Refactoring:
- Renamed the global root logger from
logto_root_logwithin the logging module to clarify its role and avoid confusion with user-level loggers. - Improved assertions to ensure that custom logging levels are properly attached as methods to the logger adapter.
links dump from getting to the current impl in this patch,
- https://github.com/goodboy/tractor/issues/244
- https://stackoverflow.com/questions/1095543/get-name-of-calling-functions-module-in-python
- https://docs.python.org/3/library/inspect.html#inspect.Traceback
- https://docs.python.org/3/library/inspect.html#inspect.FrameInfo
- https://tutorialreference.com/python/examples/faq/python-how-to-get-details-type-file-line-number-of-exception
- https://stackoverflow.com/questions/15883526/how-is-the-name-variable-in-a-python-module-defined
- https://stackoverflow.com/questions/247770/how-to-retrieve-a-modules-path
- https://docs.python.org/3/library/modulefinder.html#modulefinder-example
- https://pymotw.com/2/inspect/index.html#module-inspect
- https://stackoverflow.com/questions/22232201/how-in-python-find-where-exception-was-raised
- https://docs.python.org/3/library/traceback.html#tracebackexception-objects
- https://docs.python.org/3/library/traceback.html#traceback.extract_tb
- https://docs.python.org/3/library/traceback.html#framesummary-objects
- https://docs.python.org/3/reference/datamodel.html#frame-objects
- https://stackoverflow.com/questions/60691759/add-information-to-every-log-message-in-python-logging/61830838#61830838
- https://stackoverflow.com/questions/7507825/where-is-a-complete-example-of-logging-config-dictconfig/7507842#7507842