Skip to content

Set log level to DEBUG for all transports #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions docs/advanced/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ Logging
GQL uses the python `logging`_ module.

In order to debug a problem, you can enable logging to see the messages exchanged between the client and the server.
To do that, set the loglevel at **INFO** at the beginning of your code:

.. code-block:: python

import logging
logging.basicConfig(level=logging.INFO)

For even more logs, you can set the loglevel at **DEBUG**:
To do that, set the loglevel at **DEBUG** at the beginning of your code:

.. code-block:: python

Expand All @@ -21,10 +14,7 @@ For even more logs, you can set the loglevel at **DEBUG**:
Disabling logs
--------------

By default, the logs for the transports are quite verbose.

On the **INFO** level, all the messages between the frontend and the backend are logged which can
be difficult to read especially when it fetches the schema from the transport.
On the **DEBUG** log level, the logs for the transports are quite verbose.

It is possible to disable the logs only for a specific gql transport by setting a higher
log level for this transport (**WARNING** for example) so that the other logs of your program are not affected.
Expand Down
12 changes: 6 additions & 6 deletions gql/transport/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def _prepare_batch_request(
post_args = {"json": payload}

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

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

# Log the payload
if log.isEnabledFor(logging.INFO):
log.info(">>> %s", self.json_serialize(payload))
if log.isEnabledFor(logging.DEBUG):
log.debug(">>> %s", self.json_serialize(payload))

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

if log.isEnabledFor(logging.INFO):
if log.isEnabledFor(logging.DEBUG):
result_text = await response.text()
log.info("<<< %s", result_text)
log.debug("<<< %s", result_text)

except Exception:
await self.raise_response_error(response, "Not a JSON answer")
Expand Down
4 changes: 2 additions & 2 deletions gql/transport/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def _send(self, message: str) -> None:
try:
# Can raise TransportConnectionFailed
await self.adapter.send(message)
log.info(">>> %s", message)
log.debug(">>> %s", message)
except TransportConnectionFailed as e:
await self._fail(e, clean_close=False)
raise e
Expand All @@ -152,7 +152,7 @@ async def _receive(self) -> str:
# Can raise TransportConnectionFailed or TransportProtocolError
answer: str = await self.adapter.receive()

log.info("<<< %s", answer)
log.debug("<<< %s", answer)

return answer

Expand Down
2 changes: 1 addition & 1 deletion gql/transport/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _prepare_batch_request(
post_args = {"json": payload}

# Log the payload
if log.isEnabledFor(logging.INFO):
if log.isEnabledFor(logging.DEBUG):
log.debug(">>> %s", self.json_serialize(payload))

# Pass post_args to aiohttp post method
Expand Down
16 changes: 8 additions & 8 deletions gql/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def execute( # type: ignore
post_args[data_key] = payload

# Log the payload
if log.isEnabledFor(logging.INFO):
log.info(">>> %s", self.json_serialize(payload))
if log.isEnabledFor(logging.DEBUG):
log.debug(">>> %s", self.json_serialize(payload))

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

if log.isEnabledFor(logging.INFO):
log.info("<<< %s", response.text)
if log.isEnabledFor(logging.DEBUG):
log.debug("<<< %s", response.text)

except Exception:
raise_response_error(response, "Not a JSON answer")
Expand Down Expand Up @@ -344,8 +344,8 @@ def _extract_response(self, response: requests.Response) -> Any:
response.raise_for_status()
result = response.json()

if log.isEnabledFor(logging.INFO):
log.info("<<< %s", response.text)
if log.isEnabledFor(logging.DEBUG):
log.debug("<<< %s", response.text)

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

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

# Pass kwargs to requests post method
post_args.update(self.kwargs)
Expand Down
Loading