Last active
January 27, 2021 00:16
-
-
Save afr-dt/694521b5295d678a5317aeee82627901 to your computer and use it in GitHub Desktop.
Python requests logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from http.client import HTTPConnection | |
def httpclient_logging(): | |
HTTPConnection.debuglevel = 1 | |
requests_log = logging.getLogger("urllib3") | |
requests_log.setLevel(logging.WARNING) | |
requests_log.propagate = False | |
formatter = logging.Formatter( | |
"%(asctime)s [%(levelname)s] %(name)s: %(message)s" | |
) | |
file = logging.FileHandler("logs/filename.log") | |
file.setFormatter(formatter) | |
requests_log.addHandler(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment