执行日志
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Google Ads 脚本会显示两种类型的执行日志,无论是在预览模式下还是在实际执行过程中:更改日志和日志输出。
- 更改日志
更改日志会显示脚本对 Google Ads 实体执行的所有更改:实体说明、更改类型、更改前后的值以及错误(如有):

您也可以进一步过滤更改日志,使其只显示错误。
- 日志输出
如果您在脚本中执行 console.log("Hello world!");
,“Hello world!”会显示在日志中。记录少量文本在调试期间特别有用,但在实时执行期间也通常很有帮助。
假设您安排每天运行下列脚本:
let spreadsheet = SpreadsheetApp.create("Daily Report");
// Populate the spreadsheet.
// ...
console.log("Daily report ready!");
console.log(spreadsheet.getUrl());
在每次执行时,脚本都会记录新创建的电子表格的网址,以便日后轻松找到该电子表格。您还可以使用 console.warn()
或 console.error()
在日志中记录橙色或红色文本。
除了程序员指定的日志消息之外,Google Ads 脚本在执行过程中遇到的任何错误和警告也会显示在文本日志中。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[[["\u003cp\u003eGoogle Ads scripts provide two types of execution logs: Changes logs (tracking entity modifications) and Logs output (displaying script messages).\u003c/p\u003e\n"],["\u003cp\u003eChanges logs detail all alterations made by the script to Google Ads entities, including before and after values, and can be filtered to show only errors.\u003c/p\u003e\n"],["\u003cp\u003eLogs output displays messages generated by the script using \u003ccode\u003econsole.log\u003c/code\u003e, \u003ccode\u003econsole.warn\u003c/code\u003e, and \u003ccode\u003econsole.error\u003c/code\u003e, useful for debugging and providing context during live executions.\u003c/p\u003e\n"],["\u003cp\u003eErrors and warnings encountered by scripts during execution are automatically included in the text logs for troubleshooting.\u003c/p\u003e\n"]]],[],null,["# Execution Logs\n\nGoogle Ads scripts display two types of execution logs, both in preview mode and in\nreal executions: Changes logs and Logs output.\n\nChanges log\n\n: Changes logs display all changes to Google Ads entities performed by the\n script: entity description, type of change, value before and after, and errors\n (if any):\n\n:\n\n: Changes logs can be further filtered to only display errors.\n\nLogs output\n\n: If you execute `console.log(\"Hello world!\");` in a script, \"Hello\n world!\" appears in the logs. Logging bits of text is particularly useful\n during debugging, but is often helpful during live executions too.\n Suppose the following script is scheduled to run daily:\n\n let spreadsheet = SpreadsheetApp.create(\"Daily Report\");\n // Populate the spreadsheet.\n // ...\n console.log(\"Daily report ready!\");\n console.log(spreadsheet.getUrl());\n\n: In every execution, the script logs the URL of the newly created spreadsheet,\n making it easier to find later. You can also use `console.warn()` or\n `console.error()` for logging orange or red text in the logs.\n\nIn addition to programmer-specified log messages, any\n[errors and warnings](/google-ads/scripts/docs/concepts/errors) the Google Ads scripts\nencounters during execution will also appear in the text logs."]]