You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now all websocket messages are being sent at INFO level, and there's no way to change it for graphql-python (only globally). Useful information is often emitted at INFO level, but it becomes hard to read with all the websocket traffic. Especially when it fetches the initial schema (which in my case is large enough that it sometimes crashes my IDE).
It would be helpful if either:
Websocket traffic is emitted at DEBUG (which seems reasonable to me, as they're only needed when debugging).
Logging levels could be overriden just for this package.
I'm happy to make the pull request if you're open to one or the other option.
Reacted by Alexis Rolland, Eric Bieszczad-Stie and Borislav Novikov
What I wanted was to have a single level used only for the messages exchanged between the frontend and the backend, and a lower level for more even lower debug messages.
Of course this could be changed if necessary.
Please note that with the python logging module it should be possible to configure different log levels for different loggers and also for different handlers so that you could ignore the websockets logs (See logging control flow)
I also find the logging quite verbose and a bit difficult to read. When the query sent to the API is logged it contains a lot of new lines and spaces which damage the readibility. It is not the case in the response which I find more readable. Example:
Here is a small example on how to disable the logs (for the requests transport but it should work the same way for other transports)
It works by getting the logger from the transport file and changing the level for this logger only (so that all the other logs in your code are not affected).
I'll make a PR to improve the documentation about this.
importlogginglogging.basicConfig(level=logging.INFO)
fromgqlimportClient, gqlfromgql.transport.requestsimportRequestsHTTPTransportfromgql.transport.requestsimportlogasrequests_loggerrequests_logger.setLevel(logging.WARNING)
transport=RequestsHTTPTransport(
url="https://countries.trevorblades.com/", verify=True, retries=3,
)
client=Client(transport=transport, fetch_schema_from_transport=True)
query=gql(
""" query getContinents { continents { code name } } """
)
result=client.execute(query)
logging.info(f'We received the result: {result}')
Reacted by Alexis Rolland, faberchri, ניר, Jaime Avalos, Mikhail Vlasenko and Simon Sawert
Activity
leszekhanusz commentedon Dec 7, 2020
What I wanted was to have a single level used only for the messages exchanged between the frontend and the backend, and a lower level for more even lower debug messages.
Of course this could be changed if necessary.
Please note that with the python logging module it should be possible to configure different log levels for different loggers and also for different handlers so that you could ignore the websockets logs (See logging control flow)
alexisrolland commentedon Dec 12, 2020
I also find the logging quite verbose and a bit difficult to read. When the query sent to the API is logged it contains a lot of new lines and spaces which damage the readibility. It is not the case in the response which I find more readable. Example:
leszekhanusz commentedon Dec 12, 2020
Here is a small example on how to disable the logs (for the requests transport but it should work the same way for other transports)
It works by getting the logger from the transport file and changing the level for this logger only (so that all the other logs in your code are not affected).
I'll make a PR to improve the documentation about this.
faberchri commentedon Nov 12, 2021
For async I/O, I had to use
from gql.transport.aiohttp import log as requests_logger.gmagno commentedon Sep 7, 2022
For dsl I did: