[英]Google Apps Script PropertiesService - Confused by unreliable Executions logging & editor debugging
我發現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 手動調試運行,我在添加這些PropertiesServices
行之前每 15 分鍾設置一次onTrigger
。 每當我每次執行查看Execution
log頁面的時候,需要幾分鍾才能得到日志結果,而剛才,半個多小時后,我重新查看,那些Unknown
status logs都標記為Completed
,而且都在0.5s以下.
這只是一個小故障嗎? 如果這不正常或者我犯了一個錯誤/錯誤的假設,我應該怎么做才能確保我不會遇到這種不可預測的結果?
為什么我不能從props
鍵值對中獲取字符串?
對於相對更好和可靠的日志記錄,請直接使用 Stackdriver(即,查看 > Stackdriver 日志記錄),而不是從儀表板中的“執行”頁面。 為此,您需要通過在 Resources > Cloud Platform project > Change project 中設置自定義項目編號, 將 Google 雲項目從默認切換為標准。
記錄對象時,您必須始終JSON.stringify
object,然后再將其提供給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() {
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.