Skip to content

Instantly share code, notes, and snippets.

@afr-dt
Last active January 27, 2021 00:16
Show Gist options
  • Save afr-dt/694521b5295d678a5317aeee82627901 to your computer and use it in GitHub Desktop.
Save afr-dt/694521b5295d678a5317aeee82627901 to your computer and use it in GitHub Desktop.
Python requests logging
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