-
Notifications
You must be signed in to change notification settings - Fork 14
Added logger with basic debugging info #86
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
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.
This is the biggest python magic I've every seen :D. I've never worked with context variables and meta classes, but after reading up on them the usage here looks good to me. A thanks for teaching me something new!
The log records have useful properties added with the `extra` argument, | ||
like `attempt`, `status_code`, `url`, `client_method` and `resource_id`. | ||
To print those out, you'll need to use a custom log formatter. | ||
To learn more about log formatters and how to use them, | ||
please refer to the official Python [documentation on logging](https://docs.python.org/3/howto/logging.html#formatters). |
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.
Maybe it would be beneficial here to show a simple example with custom log formatter? So the users don't need to go dig in the official docs.
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.
I was trying to write something, but then I realized there's so many ways how users can have their formatters configured, and I kinda gave up. Usually, if you need logging in your app, you're already using some log formatters, and you won't be learning about them from this library.
Anyway, the logging here is most useful to us while developing the client, not so much to the users (especially the extra log properties), maybe I'll add a mention of the _DebugLogFormatter
somewhere to README or something like that.
@mhamas You're welcome! Python can be quite powerful, I'm glad we're now doing the Python SDK because I'm getting to dive deep into it. Currently about to send my first PR to CPython 😄 |
Logging was missing for a long time from the client, and it made it harder to debug the client.
This adds some basic logging to the HTTP calls, using the standard Python logger, enriched by contextual information from the client methods which are doing the HTTP calls by some funky metaclass programming.
There is a
_DebugLogFormatter
class which is great for testing, used like this: