The library can be configured to log interactions with the Google Ads API in various ways. You can log detailed requests and responses, as well as more concise summary messages. These settings are managed by the client library configuration. Below are details on the different types of configuration options that are available.

The library uses Python's built-in logging framework and logs to stderr by default. If included, the logging object defined in your configuration is passed directly to logging.config.dictConfig as a dict.

You can also configure logging programmatically by setting a logging configuration before initializing the client. You can retrieve the client logger instance and configure it with the following example:

import logging
logging.basicConfig(level=logging.INFO, format='[%(asctime)s - %(levelname)s] %(message).5000s')

Note that the client logger is configured when the client is initialized. Any subsequent changes to the logging configuration will be ignored. In order to programmatically override the logging configuration in the YAML file, be sure to call the above lines before the client is initialized.

Log levels

The client generates logs at a few different levels and you can set your configuration to see some or all of the below:

Level Successful Request Failed Request
DEBUG A detailed log with complete request and response objects as JSON. A detailed log with complete request and exception objects as JSON.
INFO A concise summary with specific request and response fields. A detailed log with complete request and exception objects as JSON.
WARNING None A concise summary with specific request information, the exception state and message.

Since the Python logging framework ignores log messages that are less severe than the configured level, setting to WARNING means you will only see concise messages related to failed requests, but setting to DEBUG means you will see all possible types of logs in the above table.

Logging to file

You can easily pipe log messages to a file; for example, when running the get_campaigns example::

python get_campaigns.py -c $CLIENT_ID 2> example.log

Logging interceptors

The Python client library uses gRPC interceptors to access and log request and response details. You can set up your own custom logging by creating a gRPC interceptor with custom logic. See the Logging guide for more details and an example of a custom logging interceptor.