[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eThe Google Ads API Python client library offers configurable logging for interactions, allowing detailed or summary logs of requests and responses.\u003c/p\u003e\n"],["\u003cp\u003eLogging is managed via the client library configuration and utilizes Python's built-in logging framework, outputting to \u003ccode\u003estderr\u003c/code\u003e by default.\u003c/p\u003e\n"],["\u003cp\u003eLog levels can be adjusted (\u003ccode\u003eDEBUG\u003c/code\u003e, \u003ccode\u003eINFO\u003c/code\u003e, \u003ccode\u003eWARNING\u003c/code\u003e) to control the verbosity and types of logged information, impacting visibility into successful and failed requests.\u003c/p\u003e\n"],["\u003cp\u003eLogs can be directed to a file for persistent storage, and custom logging interceptors can be implemented for tailored logging behavior beyond the library's built-in options.\u003c/p\u003e\n"]]],[],null,["# Enable Logging\n\nThe library provides versatile logging for Google Ads API interactions. You can\ncapture:\n\n- Detailed information: Full requests sent to the API and responses received.\n- Concise summaries: A high-level overview of the interactions.\n\nAnd you can control these logging settings in two ways:\n\n- Client Library Configuration: Use the library's specific [configuration](/google-ads/api/docs/client-libs/python/configuration) options.\n- Programmatically with Python: Use Python's built-in [logging](//docs.python.org/3.7/library/logging.html) framework for more direct control.\n\nLogging is configured automatically when a `GoogleAdsClient` instance is\ninitialized. This initialization step occurs, for example, when you use the\n`load_from_storage` method. At this point, the library will:\n\n- Read your specified logging settings from its [configuration](/google-ads/api/docs/client-libs/python/configuration).\n- Pass these settings to Python's built-in [`logging.config.dictConfig`](//docs.python.org/3.7/library/logging.config.html#logging.config.dictConfig) to activate them.\n\nWhen this library is used as an installed package, you need to integrate its\nlogging with your application's logging setup. Specifically, you must add a\nlogging handler to the library's own logger instance with the\n[`addHandler`](//docs.python.org/3/library/logging.html#logging.Logger.addHandler)\nmethod. This handler will dictate where the library's log messages are directed\n(e.g., to the console, a file, etc.). To do this, first retrieve the library's\nlogger instance as shown here: \n\n import logging\n\n logger = logging.getLogger('google.ads.googleads.client')\n\nAfter retrieving the library's logger, you can tell it where to output log\nmessages.\n\n- Sending Logs to the Console: To display log messages on your console, you\n add a basic handler. Here's how to direct logs to standard output (`stdout`):\n\n And here's how to set a basic handler that will tell the logger to print to\n `stdout`: \n\n import sys\n\n # Assuming 'logger' was retrieved as per previous instructions\n logger.addHandler(logging.StreamHandler(sys.stdout))\n\n If you prefer to send logs to standard error (`stderr`), which is often used\n for error messages and warnings: \n\n import sys\n\n # Assuming 'logger' was retrieved as per previous instructions\n logger.addHandler(logging.StreamHandler(sys.stderr))\n\n- Configuring Other Logging Settings Programmatically: Once you have the\n logger object, you can also programmatically change other logging settings\n using Python's built-in [logging](//docs.python.org/3.7/library/logging.html)\n module. For example, to change the logging level to `DEBUG` (which will show\n more detailed messages):\n\n logger.setLevel(logging.DEBUG)\n\nLog levels\n----------\n\nThe client generates logs at a few different levels and you can set your\nconfiguration to see some or all of the below:\n\n| Level | Successful Request | Failed Request |\n|-----------|--------------------------------------------------------------------|---------------------------------------------------------------------------------------|\n| `DEBUG` | A detailed log with complete request and response objects as JSON. | A detailed log with complete request and exception objects as JSON. |\n| `INFO` | A concise summary with specific request and response fields. | A detailed log with complete request and exception objects as JSON. |\n| `WARNING` | None | A concise summary with specific request information, the exception state and message. |\n\nSince the Python logging framework ignores log messages that are less severe\nthan the configured level, setting to `WARNING` means you will only see\nconcise messages related to failed requests, but setting to `DEBUG` means\nyou will see all possible types of logs in the above table.\n\nLogging to file\n---------------\n\nWhen you run example scripts like\n[`get_campaigns.py`](//github.com/googleads/google-ads-python/blob/main/examples/basic_operations/get_campaigns.py)\nfrom your command line, any log messages typically printed to the console can\nbe redirected (or \"piped\") to a file. This is a feature of your operating\nsystem's shell, not the Python library itself. Here's how:\n\nTo save standard output (most logs) to a file (overwriting it): \n\n python get_campaigns.py -c $CLIENT_ID \u003e campaign_logs.txt\n\nTo append standard output to a file: \n\n python get_campaigns.py -c $CLIENT_ID \u003e\u003e campaign_logs.txt\n\nTo save both standard output and standard error (for errors/warnings) to the\nsame file: \n\n python get_campaigns.py -c $CLIENT_ID \u003e all_logs.txt 2\u003e&1\n\n(Or, on some modern shells like Bash 4+): \n\n python get_campaigns.py -c $CLIENT_ID &\u003e all_logs.txt\n\nLogging interceptors\n--------------------\n\nThe Python client library uses gRPC\n[interceptors](//grpc.io/blog/grpc-web-interceptor) to access and log request\nand response details. You can set up your own custom logging by creating a gRPC\ninterceptor with custom logic. See the [Logging\nguide](/google-ads/api/docs/best-practices/logging#option_4_implement_a_custom_grpc_logging_interceptor)\nfor more details and an example of a custom logging interceptor."]]