-
Notifications
You must be signed in to change notification settings - Fork 141
Fixes ignored --loglevel by adding force=True when configuring with basicConfig. #800
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
Fixes ignored --loglevel by adding force=True when configuring with basicConfig. #800
Conversation
Setting force=True removes any existing handlers from the root logger before configuring it. If not specified, the changes are not applied. During the import process there are other calls to logging.basicConfig. Specificially, when tensorflow is not installed, then datumaro/components/extractor_tfds.py:26 calls log.debug, which in turn calls log.basicConfig. Since the call to basicConfig in datumaro/cli/__main__.py is the only deliberate call to basicConfig, it should be forced and overwrite any other inadvertent config changes.
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.
Hi @Lucas-Steinmann, thank you for contributing to this project. It looks good to me but there is a formatting problem. Would you please fix it?
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.
Some failures are found in our unit tests.
By introducing force=True to log.basicConfig in a previous commit, log capturing handlers which have been added by the unit tests are removed. This commit implements a less drastical way to configure logging. Instead of removing all handlers, this simply sets the log level and overwrites the formatter. In doing so the CapturingHandlers of the unit tests are preserved, but the log level as well as the format is still set. This is a compromise, since it tries to handle cases where logging is already configured but still does some changes to the logging behaviour. It would be laborious to anticipate every possible previous log configuration. Hence, this commit only tries to fix the special case to make unit tests similar to tests/cli/test_video::VideoTest.test_can_display_video_import_warning_in_import compatible.
I've fixed the formatting and I've revisited the tests. The main problem is that the tests overwrite the logging configuration. I've tried to find a compromise, by not deleting handlers and instead only overwriting log level and formatters. |
Codecov ReportBase: 84.01% // Head: 83.95% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #800 +/- ##
===========================================
- Coverage 84.01% 83.95% -0.07%
===========================================
Files 174 174
Lines 22956 22927 -29
Branches 4985 4971 -14
===========================================
- Hits 19287 19248 -39
- Misses 2546 2552 +6
- Partials 1123 1127 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
It seems that the previous implementation ( |
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.
Setting
force=True
removes any existing handlers from the root logger before configuring it.If not specified and any handlers have been set before the call to basicConfig, then the changes are not applied.
During the import process, there are other calls to
logging.basicConfig
. Specifically, when tensorflow is not installed, then this line callslog.debug
, which in turn callslog.basicConfig
.Since the call to basicConfig in
datumaro/cli/__main__.py
is the only deliberate call to basicConfig, it should be forced and overwrite any other inadvertent config changes.Summary
Resolves #627
Fixes bug, which prevented setting of log level when calling CLI tool.
How to test
Before this patch is applied setting
--loglevel
did nothing (atleast if tensorflow is not installed, haven't tested with tf).To test it just check if calling
datum --loglevel debug <any command>
works before and after applying this test.Checklist
develop
branchLicense
Feel free to contact the maintainers if that's a concern.