-
Notifications
You must be signed in to change notification settings - Fork 179
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
Logging is too verbose #178
Comments
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. import logging
logging.basicConfig(level=logging.INFO)
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
from gql.transport.requests import log as requests_logger
requests_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}') |
For async I/O, I had to use |
For dsl I did: from gql.dsl import log as dsl_logger
dsl_logger.setLevel(logging.WARNING) |
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 atINFO
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:
DEBUG
(which seems reasonable to me, as they're only needed when debugging).I'm happy to make the pull request if you're open to one or the other option.
The text was updated successfully, but these errors were encountered: