-
Notifications
You must be signed in to change notification settings - Fork 27
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
π¨ Improving servicelib.logging_utils
#6224
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6224 +/- ##
=========================================
+ Coverage 84.5% 87.8% +3.2%
=========================================
Files 10 1143 +1133
Lines 214 50332 +50118
Branches 25 780 +755
=========================================
+ Hits 181 44222 +44041
- Misses 23 5939 +5916
- Partials 10 171 +161
Flags with carried forward coverage won't be shown. Click here to find out more.
|
servicelib.logging_utils
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, please see my question below.
FYI: I would not mind us moving towards loguru.
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, I don't see where loguru say they are asyncio compatible. can you point that please?
@sanderegg they seem to provide support to enqueue logs asyncronously. https://loguru.readthedocs.io/en/stable/overview.html#asynchronous-thread-safe-multiprocess-safe |
@pcrespov then please also check with this: |
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
Quality Gate passedIssues Measures |
What do these changes do?
Addresses some issues with
servicelib.logging_utils
:log_decorator
to log only inlevel
log_exceptions
context managerMotivation
The idea of
log_decorator
is to log inputs/outputs of a function. Inputs are the function arguments and are logged before calling the function. Outputs are either returned values or exceptions which are logged after the call.Let's look at this example. Assume I decorate
foo
to log in debug modeand then use it inside another function where I handle the exceptions it might raise
Then, when I call
safe_foo(-1)
what would you expect in the logs. I would expect aDEBUG
trace for allfoo
calls. Instead I was getting something likeBut, didn't I handled that error? Why the function exception is logged as
ERROR
if I am logging my function asDEBUG
.The issues was introduced when we introduced
log_catch
within `log_decorator.Thoughts
Logging should follow very rationale and the fucntions hsould have very similar signatures to builtin
logging
Composition of context managers can also be implemented using
contextlib.ExitStack
Proposal
This is taking too much time and effort to get it right. I think we should move to something like loguru and even get
asyncio
improvement for free! On lets implement https://superfastpython.com/asyncio-logging-best-practices/Related issue/s
How to test
cd packages/service-library make install-dev pytest -vv tests/test_logging_utils