猿问

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

我发现它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 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 手动调试运行,我onTrigger在添加这些PropertiesServices行之前每 15 分钟设置一次。每当我每次执行的时候查看Executionlog页面,几分钟就可以得到日志结果,而刚才,半个多小时后,我重新查看,那些状态日志都被标记了,都在0.5sUnknown以内Completed。


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


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


侃侃无极
浏览 134回答 2
2回答

慕莱坞森

对于相对更好和可靠的日志记录,请直接使用 Stackdriver(即,查看 > Stackdriver 日志记录),而不是从仪表板中的“执行”页面。为此,您需要通过在 Resources > Cloud Platform project > Change project 中设置自定义项目编号,将Google 云项目从默认切换为标准。记录对象时,您必须始终JSON.stringify在将对象提供给console. props.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>

白板的微信

这似乎工作得很好:function testprops() {&nbsp; let sp = PropertiesService.getScriptProperties();&nbsp; sp.setProperties({'somekey': Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "yyyy:MM:dd HH:mm:ss")});&nbsp; let props = sp.getProperties();&nbsp; SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(props.somekey), "View Properties");}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答