-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement and standardize logging configuration via config file #1095
Implement and standardize logging configuration via config file #1095
Conversation
ela-kotulska-frequenz
commented
Nov 4, 2024
•
edited
Loading
edited
- Add LoggerConfig and LoggingConfig to standardize logging configuration.
- Create LoggingConfigUpdater to handle runtime config updates.
- Support individual log level settings for each module.
c3f4aca
to
35ab5ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All comments optional, except for the test, I think it is important to test the _update_logging()
method.
# Check if default config has been set | ||
logging_mock.basicConfig.assert_called_once() | ||
|
||
update_logging_spy = mocker.spy(actor, "_update_logging") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I didn't know about spy
. But with this you are not actually testing the _update_logging
method itself. I would either change this test or add another test and mock logging.getLogger
to verify it is being called as expected, or maybe even just instead the real logging
(basically l = logging.getLogger(...); asser l.level == expected_level
) to verify the config was actually changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, however things get more complicated. :)
- python doens't allow to override root level config in unit test (which makes sense because it can mess up other tests).
- loggings setings for other loggers are not reset after unit test method ends, I had to write teardown method (pytest.fixture) to reset them manually. Please look at test.
Also I found bug - with new config, old loggers were not unset. It is fixed and tested.
I am not testing root_logging level, but I think it is ok, because then we start testing external library.
I could check if logging.basicConfig was called with correct arguments, but I am not sure it it valuable check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think for that case you can just mock the logging.getLogger()
function and just trust that if it is called with the right parameters it will work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, agree with Luca on renaming default to root.
81a11da
to
f0406ff
Compare
Old version had a but: with new config, old loggers were not unset. It is fixed and tested, now. |
Ah, good catch! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one missing update of default
-> root_logger
and it is good to go!
* Add LoggerConfig and LoggingConfig to standardize logging configuration. * Create LoggingConfigUpdater to handle runtime config updates. * Support individual log level settings for each module.i Signed-off-by: Elzbieta Kotulska <[email protected]>
f0406ff
to
ce73140
Compare
It's nice to see the config stuff getting some love and being put in the SDK 🎉 |