| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f86fb8e commit 0d4de01
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1540,6 +1540,39 @@ def _set_auth_info(self) -> None: | |||
| 1540 | 1540 | self.http_username, self.http_password | |
| 1541 | 1541 | ) | |
| 1542 | 1542 | ||
| 1543 | + def enable_debug(self, mask_credentials: bool = True) -> None: | ||
| 1544 | + import logging | ||
| 1545 | + from http import client | ||
| 1546 | + | ||
| 1547 | + client.HTTPConnection.debuglevel = 1 | ||
| 1548 | + logging.basicConfig() | ||
| 1549 | + logger = logging.getLogger() | ||
| 1550 | + logger.setLevel(logging.DEBUG) | ||
| 1551 | + | ||
| 1552 | + httpclient_log = logging.getLogger("http.client") | ||
| 1553 | + httpclient_log.propagate = True | ||
| 1554 | + httpclient_log.setLevel(logging.DEBUG) | ||
| 1555 | + | ||
| 1556 | + requests_log = logging.getLogger("requests.packages.urllib3") | ||
| 1557 | + requests_log.setLevel(logging.DEBUG) | ||
| 1558 | + requests_log.propagate = True | ||
| 1559 | + | ||
| 1560 | + # shadow http.client prints to log() | ||
| 1561 | + # https://stackoverflow.com/a/16337639 | ||
| 1562 | + def print_as_log(*args: Any) -> None: | ||
| 1563 | + httpclient_log.log(logging.DEBUG, " ".join(args)) | ||
| 1564 | + | ||
| 1565 | + setattr(client, "print", print_as_log) | ||
| 1566 | + | ||
| 1567 | + if not mask_credentials: | ||
| 1568 | + return | ||
| 1569 | + | ||
| 1570 | + token = self.private_token or self.oauth_token or self.job_token | ||
| 1571 | + handler = logging.StreamHandler() | ||
| 1572 | + handler.setFormatter(utils.MaskingFormatter(masked=token)) | ||
| 1573 | + logger.handlers.clear() | ||
| 1574 | + logger.addHandler(handler) | ||
| 1575 | + | ||
| 1543 | 1576 | ||
| 1544 | 1577 | class AsyncGraphQL(_BaseGraphQL): | |
| 1545 | 1578 | def __init__( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments