为了账号安全,请及时绑定邮箱和手机立即绑定

Google Apps Script PropertiesService - 被不可靠的执行日志记录

Google Apps Script PropertiesService - 被不可靠的执行日志记录

侃侃无极 2023-04-27 16:52:27
我发现它PropertiesService不可靠,但可能我只是不熟悉 Google Apps Script 或 Stackdriver,并且犯了一个错误或假设了一些可能导致问题的地方。这是脚本:sp = PropertiesService.getScriptProperties()sp.setProperties({  'somekey': 'value'})props = sp.getProperties()console.log(props.toString())这是我写这个 SO 问题之前的日志:Type     Start Time                 Duration  Status     Stackdriver LogTrigger  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], ScriptPropertiesEditor   Oct 9, 2020, 11:05:16 PM   0 s       Unknown    Debug [object Object], ScriptProperties   标记为Editor类型的是从应用程序脚本 Web IDE 手动调试运行,我onTrigger在添加这些PropertiesServices行之前每 15 分钟设置一次。每当我每次执行的时候查看Executionlog页面,几分钟就可以得到日志结果,而刚才,半个多小时后,我重新查看,那些状态日志都被标记了,都在0.5sUnknown以内Completed。这只是一个小故障吗?如果这不正常或者我犯了一个错误/错误的假设,我应该怎么做才能确保我不会遇到这种不可预测的结果?为什么我不能从props键值对中获取字符串?
查看完整描述

2 回答

?
慕莱坞森

TA贡献1810条经验 获得超4个赞

  • 对于相对更好和可靠的日志记录,请直接使用 Stackdriver(即,查看 > Stackdriver 日志记录),而不是从仪表板中的“执行”页面。为此,您需要通过在 Resources > Cloud Platform project > Change project 中设置自定义项目编号,将Google 云项目从默认切换为标准。

  • 记录对象时,您必须始终JSON.stringify在将对象提供给consoleprops.toString()只会返回[object Object]它的内部结构。

/*<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>


查看完整回答
反对 回复 2023-04-27
?
白板的微信

TA贡献1883条经验 获得超3个赞

这似乎工作得很好:


function testprops() {

  let sp = PropertiesService.getScriptProperties();

  sp.setProperties({'somekey': Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "yyyy:MM:dd HH:mm:ss")});

  let props = sp.getProperties();

  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(props.somekey), "View Properties");

}


查看完整回答
反对 回复 2023-04-27
  • 2 回答
  • 0 关注
  • 92 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信