日志记录
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通过 Google Ads API 发出的请求、收到的响应和生成的摘要消息可以使用您自己的自定义记录器或 Perl 客户端库中的默认记录器进行记录。
日志级别
该库会将不同类型的事件记录到不同的日志级别。如果 API 响应成功,系统会以 INFO
级别记录摘要,并以 DEBUG
级别记录完整的请求和响应。对于导致 API 错误的请求,摘要消息将记录在 WARN
中,完整请求和响应将记录在 INFO
中。
日志类型 |
日志名称 |
成功级别 |
失败级别 |
摘要 |
Google.Ads.GoogleAds.Summary |
信息 |
WARN |
详细信息 |
Google.Ads.GoogleAds.Detail |
DEBUG |
信息 |
对于部分失败,部分失败详情将记录在 DEBUG
中。
配置
客户端库使用一个自定义类来实现所有日志记录目的,并通过 GoogleAdsLogger 模块公开。此类提供了一个默认配置,可让摘要记录器和详细记录器都将日志记录到 HOME
目录下的 logs
文件夹中的相对文件。不过,您可以在 HOME
目录中提供 log4perl.conf 文件来替换默认配置。
您可以使用以下方法启用/停用日志记录:
为两个记录器启用日志记录。
Google::Ads::GoogleAds::Logging::GoogleAdsLogger::enable_all_logging();
停用摘要日志记录。
Google::Ads::GoogleAds::Logging::GoogleAdsLogger::disable_summary_logging();
停用详细日志记录。
Google::Ads::GoogleAds::Logging::GoogleAdsLogger::disable_detail_logging();
您可以直接使用 GoogleAdsLogger
类的方法,以便更好地控制请求的记录方式。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[[["\u003cp\u003eThe Google Ads API client library for Perl allows logging of requests, responses, and summaries using a custom or default logger.\u003c/p\u003e\n"],["\u003cp\u003eLogging levels include \u003ccode\u003eINFO\u003c/code\u003e, \u003ccode\u003eDEBUG\u003c/code\u003e, and \u003ccode\u003eWARN\u003c/code\u003e, used to categorize different event types like successes, failures, and partial failures.\u003c/p\u003e\n"],["\u003cp\u003eThe default logger configuration saves logs to the \u003ccode\u003elogs\u003c/code\u003e folder in your home directory, which can be customized by providing a \u003ccode\u003elog4perl.conf\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eLogging can be controlled through the \u003ccode\u003eGoogleAdsLogger\u003c/code\u003e module, allowing for enabling/disabling logging or more advanced customization.\u003c/p\u003e\n"]]],[],null,["# Logging\n\nRequests, responses, and summary messages made to the Google Ads API can be\nlogged with your own custom logger or the default logger in the client library\nfor Perl.\n\nLog Levels\n----------\n\nThe library will log different types of events to different log levels. On a\nsuccessful API response, the summary will be logged at `INFO`, and the full\nrequest and responses will be logged at `DEBUG`. On a request that resulted in\nan API error, the summary message will be logged at `WARN` and the full request\nand response will be logged at `INFO`.\n\n| Log type | Log name | Success level | Failure level |\n|----------|------------------------------|---------------|---------------|\n| SUMMARY | Google.Ads.GoogleAds.Summary | INFO | WARN |\n| DETAIL | Google.Ads.GoogleAds.Detail | DEBUG | INFO |\n\nFor partial failures, the partial failure details will be logged at `DEBUG`.\n\nConfiguration\n-------------\n\nThe client library uses a custom class for all logging purposes and is exposed\nthrough the [GoogleAdsLogger](https://github.com/googleads/google-ads-perl/blob/HEAD/lib/Google/Ads/GoogleAds/Logging/GoogleAdsLogger.pm)\nmodule. This class provides a default configuration that both summary and detail\nloggers will log to relative files in the `logs` folder under your `HOME` directory.\nBut the default configuration can be overridden by providing a\n[log4perl.conf](https://github.com/googleads/google-ads-perl/blob/HEAD/log4perl.conf)\nfile in your `HOME` directory.\n\nLogging can be enabled/disabled using the following methods:\n\n- Enables logging for both loggers.\n\n Google::Ads::GoogleAds::Logging::GoogleAdsLogger::enable_all_logging();\n\n- Disables the summary logging.\n\n Google::Ads::GoogleAds::Logging::GoogleAdsLogger::disable_summary_logging();\n\n- Disables the detail logging.\n\n Google::Ads::GoogleAds::Logging::GoogleAdsLogger::disable_detail_logging();\n\nYou can use the methods of the `GoogleAdsLogger` class directly for even more\ncontrol over how requests are logged."]]