Skip to content

DevSite Import: Logging #682

Closed
Closed

Description

@grant

Notice: This DevSite page will soon be deleted per b/133171590. Please add this sample to GitHub if it is relevant still:

https://developers.google.com/api-client-library/python/guide/logging


Logging

This page provides logging tips to help you debug your applications.

Log Level

You can enable logging of key events in this library by configuring Python's standard logging module. You can set the logging level to one of the following:

  • CRITICAL (least amount of logging)
  • ERROR
  • WARNING
  • INFO
  • DEBUG (most amount of logging)

In the following code, the logging level is set to INFO, and the Google Translate API is called:

import logging
from apiclient.discovery import build

logger = logging.getLogger()
logger.setLevel(logging.INFO)

def main():
  service = build('translate', 'v2', developerKey='your_api_key')
  print service.translations().list(
      source='en',
      target='fr',
      q=['flower', 'car']
    ).execute()

if __name__ == '__main__':
  main()

The output of this code should print basic logging info:

INFO:root:URL being requested: https://www.googleapis.com/discovery/v1/apis/translate/v2/rest
INFO:root:URL being requested: https://www.googleapis.com/language/translate/v2?q=flower&q=car&source=en&alt=json&target=fr&key=your_api_key
{u'translations': [{u'translatedText': u'fleur'}, {u'translatedText': u'voiture'}]}

HTTP Traffic

For even more detailed logging you can set the debug level of the httplib2 module used by this library. The following code snippet enables logging of all HTTP request and response headers and bodies:

import httplib2
httplib2.debuglevel = 4

Activity

  1. added
    type: docsImprovement to the documentation for an API.
    and removed
    triage meI really want to be triaged.
    on Jun 10, 2019
  2. added a commit that references this issue on Jun 26, 2019
    a73a4be
  3. grant commented on Jun 26, 2019

    @grant
    ContributorAuthor

    The docs are now added to the docs/ folder.
    Fixed with #706.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: docsImprovement to the documentation for an API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions