Effective way to debug a Google Apps Script Web Ap

2019-06-15 19:08发布

I have had some experience writing container-based apps scripts, but am totally new to web apps.

How do I debug (e.g. look at variable values, step through code etc) a web app? In a container bound script it was easy, because I could set breakpoints, use the apps script debugger - how do I go about this in a web page e.g. when I execute a doPost?

2条回答
戒情不戒烟
2楼-- · 2019-06-15 19:25

In his excellent book "Google Script", James Ferreira advocates setting up your own development environment with three browser windows; one for the code, one for the live view (in Publish, Deploy as web app, you are provided with a "latest code" link that will update the live view to the latest save when it is refreshed), and one for a spreadsheet that logs errors (using try/catch wrapped around bits of code you want to keep an eye on).

查看更多
Rolldiameter
3楼-- · 2019-06-15 19:38

In Web Apps, even the most basic debugging of variables through Logger.log() does not work!

A great solution to have at least simple variable logging available is Peter Herrmann's BetterLog for Apps Script. It allows you to log into a spreadsheet (the same as your working spreadsheet or a separate one).

Installation is very simple - just add an external resource (see the Github readme) and a single line of code to override the standard Logger object:

Logger = BetterLog.useSpreadsheet('your-spreadsheet-key-goes-here');

Remember, that the spreedsheet that you give here as a parameter will be used for the logging output and thus must be writable by anybody!

BetterLog will create a new sheet called "Log" in the given spreadsheet and will write each log call into a separate row of that sheet.

查看更多
登录 后发表回答