| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 63b2d91 commit b9041dd
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1779,3 +1779,36 @@ def _set_auth_info(self) -> None: | |||
| 1779 | 1779 | self._auth = requests.auth.HTTPBasicAuth( | |
| 1780 | 1780 | self.http_username, self.http_password | |
| 1781 | 1781 | ) | |
| 1782 | + | ||
| 1783 | + def enable_debug(self, mask_credentials: bool = True) -> None: | ||
| 1784 | + import logging | ||
| 1785 | + from http import client | ||
| 1786 | + | ||
| 1787 | + client.HTTPConnection.debuglevel = 1 | ||
| 1788 | + logging.basicConfig() | ||
| 1789 | + logger = logging.getLogger() | ||
| 1790 | + logger.setLevel(logging.DEBUG) | ||
| 1791 | + | ||
| 1792 | + httpclient_log = logging.getLogger("http.client") | ||
| 1793 | + httpclient_log.propagate = True | ||
| 1794 | + httpclient_log.setLevel(logging.DEBUG) | ||
| 1795 | + | ||
| 1796 | + requests_log = logging.getLogger("requests.packages.urllib3") | ||
| 1797 | + requests_log.setLevel(logging.DEBUG) | ||
| 1798 | + requests_log.propagate = True | ||
| 1799 | + | ||
| 1800 | + # shadow http.client prints to log() | ||
| 1801 | + # https://stackoverflow.com/a/16337639 | ||
| 1802 | + def print_as_log(*args: Any) -> None: | ||
| 1803 | + httpclient_log.log(logging.DEBUG, " ".join(args)) | ||
| 1804 | + | ||
| 1805 | + setattr(client, "print", print_as_log) | ||
| 1806 | + | ||
| 1807 | + if not mask_credentials: | ||
| 1808 | + return | ||
| 1809 | + | ||
| 1810 | + token = self.private_token or self.oauth_token or self.job_token | ||
| 1811 | + handler = logging.StreamHandler() | ||
| 1812 | + handler.setFormatter(utils.MaskingFormatter(masked=token)) | ||
| 1813 | + logger.handlers.clear() | ||
| 1814 | + logger.addHandler(handler) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments