Skip to content
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

Closed
tylermenezes opened this issue Dec 5, 2020 · 5 comments
Closed

Logging is too verbose #178

tylermenezes opened this issue Dec 5, 2020 · 5 comments
Labels
type: question or discussion Issue discussing or asking a question about gql

Comments

@tylermenezes
Copy link

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:

  1. Websocket traffic is emitted at DEBUG (which seems reasonable to me, as they're only needed when debugging).
  2. 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.

@leszekhanusz
Copy link
Collaborator

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)

@leszekhanusz leszekhanusz added the type: question or discussion Issue discussing or asking a question about gql label Dec 7, 2020
@alexisrolland
Copy link

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:

2020-12-12 09:02:07,757 - gql.transport.requests - INFO - >>> {"query": "mutation updateJobById($jobId: Int!, $jobPatch: JobPatch!) {\n  updateJobById(input: {jobPatch: $jobPatch, id: $jobId}) {\n    job {\n      id\n      title\n      status\n      progress\n      step\n      spaceId\n      configurationId\n    }\n  }\n}\n", "variables": {"jobId": 1, "jobPatch": {"status": "running"}}}
2020-12-12 09:02:07,796 - gql.transport.requests - INFO - <<< {"data":{"updateJobById":{"job":{"id":1,"title":"test","status":"running","progress":"1.00","step":1,"spaceId":1,"configurationId":1}}}}

@leszekhanusz
Copy link
Collaborator

leszekhanusz commented 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.

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}')

@faberchri
Copy link

For async I/O, I had to use from gql.transport.aiohttp import log as requests_logger.

@gmagno
Copy link

gmagno commented Sep 7, 2022

For dsl I did:

from gql.dsl import log as dsl_logger
dsl_logger.setLevel(logging.WARNING)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about gql
Projects
None yet
Development

No branches or pull requests

5 participants