Skip to content

Logging is too verbose #178

Closed
Closed

Description

@tylermenezes

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.

Activity

  1. leszekhanusz commented on Dec 7, 2020

    @leszekhanusz
    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)

  2. added
    type: question or discussion
    on Dec 7, 2020
  3. alexisrolland commented on Dec 12, 2020

    @alexisrolland

    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}}}}
    
  4. leszekhanusz commented on Dec 12, 2020

    @leszekhanusz
    Collaborator

    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}')
  5. faberchri commented on Nov 12, 2021

    @faberchri

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

  6. gmagno commented on Sep 7, 2022

    @gmagno

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: question or discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions