调试由发布请求触发的Google Apps脚本? [英] Debug a Google Apps Script which is triggered by post request?

查看:98
本文介绍了调试由发布请求触发的Google Apps脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google表格中有一个简单的脚本,该脚本由Slack中的命令触发,只是将Slack消息添加为新行.这是一个非常简单的功能,可以作为Web应用程序部署并可以正常工作:

I have a simple script in Google Sheets which is trigger by a command in Slack and just adds the Slack message as a new row. It is quite a simple function and is deployed as a web app and does work:

function doPost(req) {
var sheet = SpreadsheetApp.openById('[My Sheet Id]');
var params = req.parameters;

Logger.log(params.text);

sheet.appendRow(params.text);

return ContentService.createTextOutput("Saved your entry:" + params.text);
}

但是,Logger.log函数从不在调试日志中记录任何内容.我希望它在这里:

However the Logger.log function never logs anything in the debugging logs. I expect it to be here:

Bizarrely Executions列表也为空:

Bizarrely the Executions lists is also empty:

但是脚本正在被触发,并且正在将文本消息追加到Google工作表中.

But the script is being triggered and is appending the text message to the Google sheet.

因此,我想的问题归结为由发帖请求触发后如何从脚本(部署为Web应用程序)中准确记录日志,以及如何查看其执行情况?换句话说,您如何调试此类脚本?

So the question I suppose comes down to how exactly can I log from a script (deployed as a web app) when triggered by a post request and also how can I see its executions? In other words how do you debug such scripts?

推荐答案

远程调用doPost(e)时,它将创建一个服务器端会话,您的日志无法通过Logger.log()访问.

When a doPost(e) is invoked remotely, it creates a server-side session whose logs you cannot access via Logger.log().

但是,有另一种选择,即. StackDriver日志记录(可通过从Apps脚本编辑器菜单访问View -> StackDriver Logging ).

However, there is an alternative, ie. StackDriver Logging (accessible from the Apps Script editor menu via View -> StackDriver Logging ).

启用了StackDriver日志记录后,您需要将所有Logger.log()调用替换为console.log().

Once you have StackDriver Logging enabled, you'll need to replace all your Logger.log() calls with console.log().

这篇关于调试由发布请求触发的Google Apps脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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