graphql-python / gql

A GraphQL client in Python

Home Page:https://gql.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request/Response payloads logged at level INFO

david-waterworth opened this issue · comments

Common problems

My applications log is filled with the payload of every request/response. For example

INFO:gql.transport.requests:>>> {"query": "query IntrospectionQuery {\n  __schema {\n    queryType {\n      name\n    }\n    mutationType {\n      name\n    }\n    subscriptionType {\n      name\n    }\n    types {\n      ...FullType\n    }\n    directives {\n      name\n      description\n      locations\n      args {\n        ...InputValue\n      }\n    }\n  }\n}\n\nfragment FullType on __Type {\n  kind\n  name\n  description\n  fields(includeDeprecated: true) {\n    name\n    description\n    args {\n      ...InputValue\n    }\n    type {\n      ...TypeRef\n    }\n    isDeprecated\n    deprecationReason\n  }\n  inputFields {\n    ...InputValue\n  }\n  interfaces {\n    ...TypeRef\n  }\n  enumValues(includeDeprecated: true) {\n    name\n    description\n    isDeprecated\n    deprecationReason\n  }\n  possibleTypes {\n    ...TypeRef\n  }\n}\n\nfragment InputValue on __InputValue {\n  name\n  description\n  type {\n    ...TypeRef\n  }\n  defaultValue\n}\n\nfragment TypeRef on __Type {\n  kind\n  name\n  ofType {\n    kind\n    name\n    ofType {\n      kind\n      name\n      ofType {\n        kind\n        name\n        ofType {\n          kind\n          name\n          ofType {\n            kind\n            name\n            ofType {\n              kind\n              name\n              ofType {\n                kind\n                name\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}"}
INFO:gql.transport.requests:<<< {"data":{"__schema":{"queryType":{"name":"QueryRoot"},"mutationType":null,"subscriptionType":null,"types":[{"kind":"SCALAR","name":"Boolean","description":null,"fields":null,"inputFields":null,"interfaces":null,"enumValues":null,"possibleTypes":null}

Note this is at log level INFO, specifically

if log.isEnabledFor(logging.INFO):
log.info(">>> %s", self.json_serialize(payload))

Describe the bug
Debug messages should not be logged at INFO level

To Reproduce
Set log level to INFO

Expected behavior
If required this should be logged at DEBUG lebel

System info (please complete the following information):

  • OS: Ubuntu
  • Python version: 3.10
  • gql version: 3.5.0
  • graphql-core version: 3.2.3

Sorry, this can't be changed as it is a breaking change.
See Disabling-logs in the docs to modify the log level for gql.

bumping this issue. I see you've marked as duplicate, but is this being adressed?

@olivierpilotte it doesn't appear so, I don't understand why it cannot be changed but the maintainers consider fixing this a breaking change and closed my issue. You have to manually set the logging level per transport as per the doc link above, i.e.

from gql.transport.requests import log as requests_logger
requests_logger.setLevel(logging.WARNING)

@david-waterworth I'm running a query from Airflow, and for some reason, disabling the logs this way does not work. Not fixed in 3.6.0b0 nor 3.6.0b1

@leszekhanusz can we have a quick follow-up on this issue? Is there a plan for a permanent fix?

@olivierpilotte yes I'm seeing something similar when I enable logging in a notebook running in vscode - even though I've disabled the transport log it still generates log messages.