gpt4 book ai didi

google-apps-script - Google Apps Script .gs 文件中的 Logger.log(...) 没有输出 - 怎么了?

转载 作者:行者123 更新时间:2023-12-04 02:40:06 41 4
gpt4 key购买 nike

我有一堆服务器端代码,我使用 Logger.log("message") 从中记录。但是一个 .gs 文件没有记录!即使有这么简单的声明:

function uploadFiles(form) {
Logger.log("uploadFiles() Hello?");
...
}

如此简单,但我得到了 zilch。有谁知道为什么我无法从一个 .gs 文件中获取任何日志输出而同一项目中的其他人可以正常记录的原因?

最佳答案

回答:
使用 Logger.log() 写入的 Google Apps 脚本日志每次运行脚本时都会被清除,因此在多次调用后,只会显示最近的调用日志。
避免和正确记录:
以及可以使用 Logger.log() 写入的常规日志,Google Apps Script 有另外两种日志记录方法 - Stackdriver 日志记录和 Stackdriver 错误报告。根据 Apps 脚本文档:

Apps Script provides three different mechanisms for logging:


  • The built-in Apps Script Logger, which is lightweight but persists only for a short time.

  • The Stackdriver Logging interface in the Developer Console, which provides logs that persist for many days after their creation.

  • The Stackdriver Error Reporting interface in the Developer Console, which collects and records errors that occur while your script is running.

Stackdriver 日志记录:
当您需要比每次运行更长时间的日志记录时,首选 Stackdriver 日志。这些附加到与 Apps Script 项目相关联的 GCP 项目中,可以在 Apps Script dashboard 中找到简化版本。 .异常记录也可以通过 Stackdriver 日志完成。可以使用 console.log() 写入此日志。方法而不是 Logger.log() .
Stackdriver 错误报告:
您可以在 GCP console 中查看 Stackdriver 错误报告.
引用:
  • Google Apps Script Logging
  • Basic Logging
  • Stackdriver Logging
  • Exception Logging
  • Stackdriver Error Reporting
  • Logging Requirements
  • Google Apps Script Class Logger

  • 此答案是在其他信息曝光后更新的。由于 Google Apps Script 的 Logging 方法存在已知问题,因此原始答案保留在下方。

    这似乎是一个错误! Logger.log() function 应该记录传递给该方法的所有内容,并且无论在单个调用中运行多少个函数,调用中所有函数的所有日志都应该在记录器中可见。 只有异常(exception)是如果有太多 Logger.log()调用,并且日志被截断。
    如上所述,已经有一份关于 Google 的问题跟踪器的报告,其中详细说明了相同的行为:
  • 36764984 Visible to Public Logger.log() sometimes does not work

  • 谷歌似乎知道这个问题,但如果它导致问题,你可以提交你自己的错误 here .
    您还可以点击上述页面左上角问题编号旁边的 ☆,让 Google 知道更多人正在遇到此问题,因此更有可能更快地看到它。

    关于google-apps-script - Google Apps Script .gs 文件中的 Logger.log(...) 没有输出 - 怎么了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59792504/

    41 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com