本文介绍了Google Apps Script .gs文件中Logger.log(...)没有输出-怎么了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆服务器端代码,可以使用Logger.log("message")从中进行记录.但是一个.gs文件不会记录!即使这样简单的声明:

I have a bunch of server side code from which I log using Logger.log("message"). But one single .gs file does not log! Even with a statement as simple as this:

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

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

So simple yet I get zilch. Does anyone know a reason why I can't get any logging output from one .gs file while others in the same project can log fine?

推荐答案

答案:

Logger.log()写入的Google Apps脚本日志在每次运行脚本时都会被清除,因此在多次调用之后,只会显示最新呼叫的日志.

Answer:

The Google Apps Script Log which is written to with Logger.log() gets cleared each time the script is run, and so after multiple invokations only the most recent call's logs will be shown.

除了可以用Logger.log()写入的常规日志外,Google Apps脚本还有另外两种日志记录方法-Stackdriver logging和Stackdriver Error report.根据Apps脚本文档:

As well as the regular log which can be written to with Logger.log(), Google Apps Script has two other methods of logging - Stackdriver logging and Stackdriver Error reporting. As per the Apps Script documentation:

  • 内置的Apps脚本记录器,重量轻,但只能保留很短的时间.

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

开发者控制台中的Stackdriver Logging界面,该界面提供的日志在创建后会持续很多天.

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

开发者控制台中的Stackdriver Error Reporting界面,该界面收集并记录脚本运行时发生的错误.

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项目中,并且可以在应用脚本仪表板.异常日志记录也可以通过Stackdriver日志来完成.可以使用console.log()方法而不是Logger.log()来写入此日志.

When you requre logging that persists for a longer time than per-run, Stackdriver logs are preferred. These are attached to the GCP project that is associated with the Apps Script project, and a simplified version can be found in the Apps Script dashboard. Exception logging can also be done via the Stackdriver logs. This log can be written to by using the console.log() method rather than Logger.log().

Stackdriver错误报告:

您可以在 GCP控制台中查看您的Stackdriver错误报告. .

  • Google Apps脚本记录
    • Google Apps Script Logging
      • Basic Logging
      • Stackdriver Logging
      • Exception Logging
      • Stackdriver Error Reporting
      • Logging Requirements

      在其他信息曝光后,此答案已更新.由于Google Apps脚本的日志记录方法存在已知问题,因此原始答案保留在下面.

      Logger.log()函数应该记录传递给该方法的所有内容,并且无论在单个调用中运行了多少个功能块,该调用中所有函数的所有日志都应该在记录器中可见. 例外是Logger.log()调用过多,并且日志被截断了.

      The Logger.log() function should log everything passed to the method, and regardless of how many funcitons are run in a single call, all logs from all functions from within the call should be viewable in the logger. The only exception is if there are too many Logger.log() calls, and the logs are truncated.

      如上所述,Google的问题跟踪工具已经有一份报告,其中详细介绍了相同的行为:

      As mentioned above, There is already a report on Google's Issue Tracker which detail the same kind of behaviour:

      Google似乎确实了解此问题,但是如果引起问题,您可以提交有关此问题的错误此处.

      Google does seem to know about this issue but if it's causing problems you can file your own bug about it here.

      您还可以点击上述页面左上方发行编号旁边的☆,以使Google知道更多人正在遇到这种情况,因此更有可能看到更快的速度.

      You can also hit the ☆ next to the issue number in the top left on the aforementioned pages which lets Google know more people are encountering this and so it is more likely to be seen to faster.

      希望对您有帮助!

      这篇关于Google Apps Script .gs文件中Logger.log(...)没有输出-怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 15:26