Skip to content

Commit b9041dd

Browse files
committed
Add AsyncGraphQL.enable_debug
1 parent 63b2d91 commit b9041dd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

gitlab/client.py

+33
Original file line numberDiff line numberDiff line change
@@ -1779,3 +1779,36 @@ def _set_auth_info(self) -> None:
17791779
self._auth = requests.auth.HTTPBasicAuth(
17801780
self.http_username, self.http_password
17811781
)
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)

0 commit comments

Comments
 (0)