Skip to content
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 python standart logging for CachedResponse #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pavelsr
Copy link
Collaborator

@pavelsr pavelsr commented Sep 15, 2023

Prints

  • response.request.method
  • response.request.url
  • response.status_code

Also:

  • response.from_cache
  • response.created_at
  • response.expires
  • response.is_expired

https://requests-cache.readthedocs.io/en/stable/user_guide/inspection.html#response-details

Output will be like:

INFO:yaschedule.core:GET https://api.rasp.yandex.net/v3.0/schedule/?apikey=abc&lang=ru_RU&station=s9600366 400
INFO:yaschedule.core:Response(from_cache=False, created_at=2023-09-15 22:24:57.769567, expires=None, is_expired=False)

in case of success API response (HTTP 200) there is an extra bonus - API key is auto-hidden by requests_cache (REDACTED in log) - so logging is secure by default

$ python3 t.py 
INFO:yaschedule.core:GET https://api.rasp.yandex.net/v3.0/schedule/?apikey=REDACTED&lang=ru_RU&station=s9600366 200
INFO:yaschedule.core:Response(from_cache=True, created_at=2023-09-15 22:40:17.285982, expires=None, is_expired=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant