Skip to content

Commit 2d21100

Browse files
authored
Set logging level to DEBUG for all transports (#552)
1 parent ef49268 commit 2d21100

File tree

5 files changed

+19
-29
lines changed

5 files changed

+19
-29
lines changed

docs/advanced/logging.rst

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ Logging
44
GQL uses the python `logging`_ module.
55

66
In order to debug a problem, you can enable logging to see the messages exchanged between the client and the server.
7-
To do that, set the loglevel at **INFO** at the beginning of your code:
8-
9-
.. code-block:: python
10-
11-
import logging
12-
logging.basicConfig(level=logging.INFO)
13-
14-
For even more logs, you can set the loglevel at **DEBUG**:
7+
To do that, set the loglevel at **DEBUG** at the beginning of your code:
158

169
.. code-block:: python
1710
@@ -21,10 +14,7 @@ For even more logs, you can set the loglevel at **DEBUG**:
2114
Disabling logs
2215
--------------
2316

24-
By default, the logs for the transports are quite verbose.
25-
26-
On the **INFO** level, all the messages between the frontend and the backend are logged which can
27-
be difficult to read especially when it fetches the schema from the transport.
17+
On the **DEBUG** log level, the logs for the transports are quite verbose.
2818

2919
It is possible to disable the logs only for a specific gql transport by setting a higher
3020
log level for this transport (**WARNING** for example) so that the other logs of your program are not affected.

gql/transport/aiohttp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ def _prepare_batch_request(
175175
post_args = {"json": payload}
176176

177177
# Log the payload
178-
if log.isEnabledFor(logging.INFO):
179-
log.info(">>> %s", self.json_serialize(post_args["json"]))
178+
if log.isEnabledFor(logging.DEBUG):
179+
log.debug(">>> %s", self.json_serialize(post_args["json"]))
180180

181181
# Pass post_args to aiohttp post method
182182
if extra_args:
@@ -199,8 +199,8 @@ def _prepare_request(
199199
post_args = {"json": payload}
200200

201201
# Log the payload
202-
if log.isEnabledFor(logging.INFO):
203-
log.info(">>> %s", self.json_serialize(payload))
202+
if log.isEnabledFor(logging.DEBUG):
203+
log.debug(">>> %s", self.json_serialize(payload))
204204

205205
# Pass post_args to aiohttp post method
206206
if extra_args:
@@ -299,9 +299,9 @@ async def _get_json_result(self, response: aiohttp.ClientResponse) -> Any:
299299
try:
300300
result = await response.json(loads=self.json_deserialize, content_type=None)
301301

302-
if log.isEnabledFor(logging.INFO):
302+
if log.isEnabledFor(logging.DEBUG):
303303
result_text = await response.text()
304-
log.info("<<< %s", result_text)
304+
log.debug("<<< %s", result_text)
305305

306306
except Exception:
307307
await self.raise_response_error(response, "Not a JSON answer")

gql/transport/common/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async def _send(self, message: str) -> None:
136136
try:
137137
# Can raise TransportConnectionFailed
138138
await self.adapter.send(message)
139-
log.info(">>> %s", message)
139+
log.debug(">>> %s", message)
140140
except TransportConnectionFailed as e:
141141
await self._fail(e, clean_close=False)
142142
raise e
@@ -152,7 +152,7 @@ async def _receive(self) -> str:
152152
# Can raise TransportConnectionFailed or TransportProtocolError
153153
answer: str = await self.adapter.receive()
154154

155-
log.info("<<< %s", answer)
155+
log.debug("<<< %s", answer)
156156

157157
return answer
158158

gql/transport/httpx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _prepare_batch_request(
9292
post_args = {"json": payload}
9393

9494
# Log the payload
95-
if log.isEnabledFor(logging.INFO):
95+
if log.isEnabledFor(logging.DEBUG):
9696
log.debug(">>> %s", self.json_serialize(payload))
9797

9898
# Pass post_args to aiohttp post method

gql/transport/requests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ def execute( # type: ignore
237237
post_args[data_key] = payload
238238

239239
# Log the payload
240-
if log.isEnabledFor(logging.INFO):
241-
log.info(">>> %s", self.json_serialize(payload))
240+
if log.isEnabledFor(logging.DEBUG):
241+
log.debug(">>> %s", self.json_serialize(payload))
242242

243243
# Pass kwargs to requests post method
244244
post_args.update(self.kwargs)
@@ -282,8 +282,8 @@ def raise_response_error(resp: requests.Response, reason: str) -> NoReturn:
282282
else:
283283
result = self.json_deserialize(response.text)
284284

285-
if log.isEnabledFor(logging.INFO):
286-
log.info("<<< %s", response.text)
285+
if log.isEnabledFor(logging.DEBUG):
286+
log.debug("<<< %s", response.text)
287287

288288
except Exception:
289289
raise_response_error(response, "Not a JSON answer")
@@ -344,8 +344,8 @@ def _extract_response(self, response: requests.Response) -> Any:
344344
response.raise_for_status()
345345
result = response.json()
346346

347-
if log.isEnabledFor(logging.INFO):
348-
log.info("<<< %s", response.text)
347+
if log.isEnabledFor(logging.DEBUG):
348+
log.debug("<<< %s", response.text)
349349

350350
except requests.HTTPError as e:
351351
raise TransportServerError(
@@ -375,8 +375,8 @@ def _build_batch_post_args(
375375
post_args[data_key] = [req.payload for req in reqs]
376376

377377
# Log the payload
378-
if log.isEnabledFor(logging.INFO):
379-
log.info(">>> %s", self.json_serialize(post_args[data_key]))
378+
if log.isEnabledFor(logging.DEBUG):
379+
log.debug(">>> %s", self.json_serialize(post_args[data_key]))
380380

381381
# Pass kwargs to requests post method
382382
post_args.update(self.kwargs)

0 commit comments

Comments
 (0)