-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
requests logging is not documented, incomplete and works unexpectedly #1297
Comments
requests does no logging of its own. All logging actually done is done by urllib3 and can be set up similar to your example: import requests
import logging
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True Even if we did do logging, we would not log the data sent in a post. You can, however, do the following: response = requests.get(url)
logging.debug("Response: Status code: %d", response.status_code)
logging.debug("Request: %s %s %s", response.request.method, response.request.url, response.request.body) I'm only leaving this ticket open as a reminder for myself during the documentation refresh I have planned. |
Have you tried to run the first piece of code? I will not log anything unless you call |
No I didn't run it because I know for a fact that requests proper does no logging of its own. All logging is done by urllib3 and I strongly suspect that the logging module is only working because urllib3 is technically part of the requests namespace. I'm also writing all of this from a phone so I can't exactly run anything at the moment. |
Thanks Ian, |
Adding extra detail was proposed in #988. Here, as there, any extra logging belongs in urllib3 and should be added there. This is being discussed at urllib3/urllib3#107. |
Requests had logging before 1.0 and it was torn out during the refactor. Take from that what you will. I'm entirely indifferent on the proposal. It's up to @kennethreitz no matter what. |
AFAIK, the behavior in the example is because of python logging module itself. If "root logger" is not initialized, nothing will be outputted. Calling My guess is that the same thing happens with any python library that uses logging. If you want output (to console. file, whatever), then you need to initialize the logging to do so. |
@jvtm Thanks! Now I can update the sample code and so we can include it in the documentation. |
* Added build directory and *.egg to .gitignore * Added sphinx as setup requirement in order to be able to build documentation with `pyhton setup.py build_sphinx` modified: .gitignore modified: docs/api.rst modified: setup.py
Documents the actual logging methods #1297
@ssbarnea's pull request was merged closing this issue. |
yeah, as @jvtm said, only initialize the "root logging" could set the log active for import module, and logging module can not match "requests.packages.urllib3", but "urllib3", like: import requests
import logging
logger = logging.getLogger("urllib3")
logger.setLevel(level=logging.DEBUG)
logging.debug("") working on python 3.6 |
Currently logging in
requests
library is not properly documented.The API Changes section of the documentation reminds about the removal of the config parameter but contains no code. See http://docs.python-requests.org/en/latest/api/?highlight=logging
So this means there are a few things to do:
#1 add the above piece of code to the documentation (including the API changes section)
#2 provide proper response on few stackoverflow questions related to requests logging
#3 find a way to allow extensive logging (logging BODY too)
The text was updated successfully, but these errors were encountered: