Google Apps脚本PropertiesService-被不可靠的执行日志记录和&编辑器调试 [英] Google Apps Script PropertiesService - Confused by unreliable Executions logging & editor debugging

查看:85
本文介绍了Google Apps脚本PropertiesService-被不可靠的执行日志记录和&编辑器调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 PropertiesService 不可靠,但是可能我只是不熟悉Google Apps脚本或Stackdriver,并在这里犯了错误或假定有可能导致问题的原因.

I find PropertiesService to be unreliable, but probably I'm just not familiar with Google Apps Script or Stackdriver and made a mistake or assumed something here that may caused the problem.

这是脚本:

sp = PropertiesService.getScriptProperties()
sp.setProperties({
  'somekey': 'value'
})
props = sp.getProperties()

console.log(props.toString())

这是我写这个SO问题之前的日志:

And here's the logs before I wrote this SO question:

Type     Start Time                 Duration  Status     Stackdriver Log
Trigger  Oct 9, 2020, 11:19:07 PM   0.541 s   Completed  Debug [object Object]
Editor   Oct 9, 2020, 11:11:43 PM   0 s       Unknown    Debug [object Object]
Editor   Oct 9, 2020, 11:08:09 PM   0 s       Unknown    Debug [object Object], ScriptProperties
Editor   Oct 9, 2020, 11:05:16 PM   0 s       Unknown    Debug [object Object], ScriptProperties   

标记为 Editor 类型的是从应用脚本Web IDE进行的手动调试,我每15分钟设置一次 onTrigger ,然后再添加这些 PropertiesServices 线.每当我在每次执行中检查 Execution 日志页面时,都需要几分钟的时间来获取日志结果,而现在,在未来半个多小时的时间里,我会重新检查,而那些 Unknown状态日志标记为 Completed ,且所有记录均在0.5s之内.

The one marked as Editor type is manual debug runs from apps script web IDE, I set onTrigger every 15mins before I added those PropertiesServices lines. Whenever I check the Execution log page in each execution, it takes minutes to get the log result, and just now, more than half an hour in the future, I re-checked and those Unknown status logs are marked Completed and all under 0.5s.

这只是一个小故障吗?如果这不正常或我做出了错误/错误的假设,我应该怎么做才能确保我不会遇到这种不可预测的结果?

Is this just a glitch? If it's not normal or I made a mistake/wrong assumption, what am I supposed to do to ensure I don't experience this kind of unpredictable results?

为什么我不能从 props 键值对中获得字符串?

Why don't I get strings from the props key value pair?

推荐答案

  • 为了获得相对更好和可靠的日志记录,请直接使用Stackdriver(即View> Stackdriver日志记录),而不要从执行"菜单中使用.仪表板中的页面.为此,您需要将Google云项目从默认设置切换为标准,方法是在参考资料>中设置自定义项目编号云平台项目>更改项目.

    • For relatively better and reliable logging, Use Stackdriver directly(i.e., View> Stackdriver logging) rather than from the "executions" page in the dashboard. To do this, you need to switch Google cloud project from default to standard by setting a custom project number in Resources > Cloud Platform project > Change project.

      记录对象时,必须始终对对象进行 JSON.stringify ,然后再将其提供给 console . props.toString()将仅返回 [object Object] ,因为它是内部结构.

      When logging objects, You must always JSON.stringify the object before feeding it to console. props.toString() will only return [object Object] as that is it's internal structure.

      /*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
      const props = {a:1};
      console.log(props.toString());//[object Object]
      console.log(JSON.stringify(props));//{"a":1}

      <!-- https://meta.stackoverflow.com/a/375985/ -->    <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>

      这篇关于Google Apps脚本PropertiesService-被不可靠的执行日志记录和&amp;编辑器调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆