blob: 408a20ac6f72cceda031ad0f82fd92222f125ebf [file] [log] [blame] [view]
Grant Timmerman5c11b0a2019-06-26 07:39:48 -07001# Logging
2
3This page provides logging tips to help you debug your applications.
4
5## Log Level
6
7You can enable logging of key events in this library by configuring Python's standard [logging](http://docs.python.org/library/logging.html) module. You can set the logging level to one of the following:
8
9- CRITICAL (least amount of logging)
10- ERROR
11- WARNING
12- INFO
13- DEBUG (most amount of logging)
14
15In the following code, the logging level is set to `INFO`, and the Google Translate API is called:
16
Bu Sun Kim8496ebe2019-08-12 18:04:35 -070017```python
Grant Timmerman5c11b0a2019-06-26 07:39:48 -070018import logging
Bu Sun Kim8496ebe2019-08-12 18:04:35 -070019from googleapiclient.discovery import build
Grant Timmerman5c11b0a2019-06-26 07:39:48 -070020
21logger = logging.getLogger()
22logger.setLevel(logging.INFO)
23
24def main():
25 service = build('translate', 'v2', developerKey='your_api_key')
26 print service.translations().list(
27 source='en',
28 target='fr',
29 q=['flower', 'car']
30 ).execute()
31
32if __name__ == '__main__':
33 main()
34```
35
36The output of this code should print basic logging info:
37
38```
39INFO:root:URL being requested: https://www.googleapis.com/discovery/v1/apis/translate/v2/rest
40INFO: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
41{u'translations': [{u'translatedText': u'fleur'}, {u'translatedText': u'voiture'}]}
42```
43
44## HTTP Traffic
45
46For even more detailed logging you can set the debug level of the [httplib2](https://github.com/httplib2/httplib2) module used by this library. The following code snippet enables logging of all HTTP request and response headers and bodies:
47
Bu Sun Kim8496ebe2019-08-12 18:04:35 -070048```python
Grant Timmerman5c11b0a2019-06-26 07:39:48 -070049import httplib2
50httplib2.debuglevel = 4
51```