Set logger parents and levels#108
Conversation
Codecov Report
@@ Coverage Diff @@
## main #108 +/- ##
==========================================
+ Coverage 88.83% 88.94% +0.10%
==========================================
Files 11 11
Lines 2069 2098 +29
==========================================
+ Hits 1838 1866 +28
- Misses 231 232 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
|
I'm adding additional tests, the C code isn't quite right yet. |
|
I like the approach, it seems clean and shouldn't really impact the performance of the critical path. In the tests, it'll be important to use docstrings to describe the setup of the test, e.g.: def test_scenario_1():
"""
Before:
root - 100
-- child 1 (NOTSET) - effective 100
-- child 2 (200) - effective 200
After:
root - 200
-- child 1 (NOTSET) - effective 200
-- child 2 (200) - effective 300?
""" |
|
If you write a detailed docstring like that, Github copilot will probably write the test for you as well :-) |
|
I just ran the tests from the CPython test_logging.py file that I had previously marked as unable to pass due to lack of hierarchy support, and they all pass! I could add the CPython tests here, but I think my current tests are pretty good coverage. |
|
TODO:
|
This is my proposal for handling levels in the logger hierarchy in a way which doesn't require parent traversal on every logging call.
This PR adds two new properties to Logger:
effective_levelandchildren. Theeffective_levelis based on thelevelof the parents, or is equal tolevelif that's explicitly set withsetLevel. WhensetLevelis called on a logger withchildren, then thatlevelbecomes theeffective_levelof any child with alevelofNOT_SET.I believe it is necessary to keep track of both
levelandeffective_levelso that we know which children's effective levels would be affected by a parent change.Let me know what you think of this approach.