-
Notifications
You must be signed in to change notification settings - Fork 62
Replace logging
with loguru
#467
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #467 +/- ##
===========================================
+ Coverage 99.87% 100.00% +0.12%
===========================================
Files 28 28
Lines 1559 1549 -10
===========================================
- Hits 1557 1549 -8
+ Misses 2 0 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
80a692d
to
93fbbc7
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.
Thanks @lochhh!
I tried using movement
through Python console and jupyter notebooks, while also keeping an eye on the log file, and this PR seems to work as advertised. Also kudos for maintaining a somewhat backwards-consistent way for us to raise errors and warnings (the syntax is very similar to what we had before).
I think this is good to go, barring a few not-so-important comments I've left.
Also make sure to rebase to main
so the changes in logging also apply to recently added stuff. One case which might be tricky is the deprecation warning I added in #455 (in filtering.py
). Ideally we want to use the new syntax for it but also ensure that specifically a DeprecationWarning
is raised.
593c5b8
to
8dea9c1
Compare
Co-authored-by: Niko Sirmpilatze <[email protected]>
8dea9c1
to
bda1c1e
Compare
2e54f6a
to
1ebca34
Compare
1afc664
to
8b2c391
Compare
Thanks @niksirbi. |
Thanks @lochhh. I think you did a great job with this. I benefitted a lot from reading your updated PR description, because when to use logger/warnings/print was not entirely clear in my mind. I have only one final request to make: could you copy some of that information over to the contributing guide? It would be good to have a canonical place to point contributors to, when we inevitably have to explain this again. |
|
Added a section describing this in Development guidelines |
* Replace `logging` with `loguru` * Combine consecutive `logger.info` calls * Configure console and file handler for logger * Use default stderr handler * Refactor logging and its tests * Use loguru default format for logging * Simplify tests logger setup * Clean up log_warning calls * Use custom MovementLogger * Remove commented out code * Fix logger repr test * Apply test docstring suggestions from code review Co-authored-by: Niko Sirmpilatze <[email protected]> * Reduce number of log files kept at rotation * Fix up rebase error * Redirect warnings to logger * Clarify caplog fixture * Refactor tests * Use default `enqueue=False` * Emit and log warning in `_warn_about_nan_proportion` * Emit warning when converting str to list[str] * Emit warning when setting fps to None * Add logging section to contributing guide --------- Co-authored-by: Niko Sirmpilatze <[email protected]>
This PR supersedes #412
Description
What is this PR
Why is this PR needed?
This PR closes #337.
What does this PR do?
Custom loguru-based
MovementLogger
This PR replaces the use of the
logging
module withloguru
. It extends loguru'slogger
with a customMovementLogger
that overrideslogger.error
andlogger.exception
to return the Exception being logged. This means that we can raise e.g.err = ValueError("message")
withinstead of
By default, the logger is configured to log to a rotating log file (at DEBUG level) and to stderr (at WARNING level). One can also turn off logging to stderr with
logger.configure(console=False)
.Standardised logging calls
All logging calls are now standardised such that we no longer have special syntaxes for logging warnings and errors:
log_warning
,log_error
, we now use the same syntax (logger.<method>()
to log at various levels, e.g.logger.error(...)
,logger.info(...)
).Single test log file
When running tests, messages are now logged to a single
movement-test.log
file configured at the beginning of each pytest session, instead of creating a new log file for each test.Integration with
warnings
moduleMessages emitted by the
warnings
module are also redirected to the logger to additionally be logged usinglogger.warning()
by replacingwarnings.showwarning
with a customshowwarning
.print
vswarnings
vslogger
This PR also ensures the appropriate use of
print
,warnings.warn
,logger.<method>
according to the when to use logger/print/warnings guide . To distinguish betweenlogger.warning()
andwarnings.warn()
, the former is used when something is optional and we assign default values (e.g. individual names, keypoint names, confidence values); the latter is used when the input from the user is invalid and can be fixed by the user within movement (e.g. deprecated function calls, invalid fps number, single individual name provided as str instead of list[str]) or when applying filters to data containing excessive NaNs, which can potentially be addressed using movement's interpolate.References
#337
How has this PR been tested?
Tests passing on CI and locally
Checklist: