[英]Google Apps Script PropertiesService - Confused by unreliable Executions logging & editor debugging
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.我发现
PropertiesService
不可靠,但可能我只是不熟悉 Google Apps Script 或 Stackdriver,犯了一个错误或假设了一些可能导致问题的地方。
Here's the script:这是脚本:
sp = PropertiesService.getScriptProperties()
sp.setProperties({
'somekey': 'value'
})
props = sp.getProperties()
console.log(props.toString())
And here's the logs before I wrote this SO question:这是我写这个 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
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.标记为
Editor
类型的是从应用程序脚本 web IDE 手动调试运行,我在添加这些PropertiesServices
行之前每 15 分钟设置一次onTrigger
。 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.每当我每次执行查看
Execution
log页面的时候,需要几分钟才能得到日志结果,而刚才,半个多小时后,我重新查看,那些Unknown
status logs都标记为Completed
,而且都在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?
如果这不正常或者我犯了一个错误/错误的假设,我应该怎么做才能确保我不会遇到这种不可预测的结果?
Why don't I get strings from the props
key value pair?为什么我不能从
props
键值对中获取字符串?
For relatively better and reliable logging, Use Stackdriver directly(ie, View> Stackdriver logging) rather than from the "executions" page in the dashboard.对于相对更好和可靠的日志记录,请直接使用 Stackdriver(即,查看 > Stackdriver 日志记录),而不是从仪表板中的“执行”页面。 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.
为此,您需要通过在 Resources > Cloud Platform project > Change project 中设置自定义项目编号, 将 Google 云项目从默认切换为标准。
When logging objects, You must always JSON.stringify
the object before feeding it to console
.记录对象时,您必须始终
JSON.stringify
object,然后再将其提供给console
。 props.toString()
will only return [object Object]
as that is it's internal structure. 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>
This seems to work just fine:这似乎工作得很好:
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");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.