@@ -70,6 +70,51 @@ retrieve the corresponding service client instance:
7070
7171 google_ads_service = client.get_service(' GoogleAdsService' )
7272
73+ Enabling and Configuring logging
74+ ################################
75+ The library uses Python's built in logging framework. You can specify your
76+ configuration via the configuration file; see `google-ads.yaml `_
77+ for an example. The library logs to ``stderr `` by default. You can easily pipe
78+ log messages to a file; when running an example:
79+
80+ .. code-block :: bash
81+
82+ python example.py args 2> example.log
83+
84+ It's also possible to configure logging programmatically using `Python's
85+ built-in logging library `_ by setting a logging configuration *before *
86+ initializing the client. You can retrieve the client logger instance and
87+ configure it with the following example:
88+
89+ .. code-block :: python
90+
91+ logging.basicConfig(level = logging.INFO , format = ' [%(asctime)s - %(levelname)s ] %(message).5000s ' )
92+ logging.getLogger(' google.ads.google_ads.client' ).setLevel(logging.INFO )
93+
94+ **NOTE: ** The client logger is configured when the client is initialized, so if
95+ you have logger configurations in your google-ads.yaml file and you want to
96+ override them programmatically, you will need to call the above lines _before_
97+ initializing the client, otherwise the configuration from yaml will take
98+ precedent as it's provided first.
99+
100+ The client generates logs at a few different levels and you can set your
101+ configuration to see some or all of the below:
102+
103+ +-------------+--------------------------------------------------------------------+---------------------------------------------------------------------------------------+
104+ | Level | Successful Request | Failed Request |
105+ +=============+====================================================================+=======================================================================================+
106+ | ``DEBUG `` | A detailed log with complete request and response objects as JSON. | None |
107+ +-------------+--------------------------------------------------------------------+---------------------------------------------------------------------------------------+
108+ | ``INFO `` | A concise summary with specific request and response fields. | A detailed log with complete request and exception objects as JSON. |
109+ +-------------+--------------------------------------------------------------------+---------------------------------------------------------------------------------------+
110+ | ``WARNING `` | None | A concise summary with specific request information, the exception state and message. |
111+ +-------------+--------------------------------------------------------------------+---------------------------------------------------------------------------------------+
112+
113+ Since the Python logging framework ignores log messages that are less severe
114+ than the configured level, setting to ``WARNING `` means you will only see
115+ concise messages related to failed requests, but setting to ``DEBUG `` means
116+ you will see all possible types of logs in the above table.
117+
73118Miscellaneous
74119-------------
75120
@@ -83,16 +128,19 @@ Authors
83128
84129* `Mark Saniscalchi `_
85130* `David Wihl `_
131+ * `Ben Karl `_
86132
87133.. _pip : https://pip.pypa.io/en/stable/installing
88134.. _template : https://github.com/googleads/google-ads-python/blob/master/google-ads.yaml
89135.. _Authorization guide : https://developers.google.com/google-ads/api/docs/oauth/overview
90136.. _authentication samples : https://github.com/googleads/google-ads-python/blob/master/examples/authentication
91137.. _Obtain your developer token : https://developers.google.com/google-ads/api/docs/first-call/dev-token
138+ .. _google-ads.yaml : https://github.com/googleads/google-ads-python/blob/master/google-ads.yaml
139+ .. _Python's built-in logging library : https://docs.python.org/2/library/logging.html
92140.. _Wiki : https://github.com/googleads/google-ads-python/wiki
93141.. _Issue tracker : https://github.com/googleads/google-ads-python/issues
94142.. _API documentation : https://developers.google.com/google-ads/api/
95143.. _API Support : https://developers.google.com/adwords/api/community/
96144.. _Mark Saniscalchi : https://github.com/msaniscalchi
97145.. _David Wihl : https://github.com/wihl
98-
146+ .. _ Ben Karl : https://github.com/BenRKarl
0 commit comments