Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effective way to debug a Google Apps Script Web App

I have had some experience writing container-bound 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?

like image 307
BruceM Avatar asked Jul 15 '12 16:07

BruceM


People also ask

How do you debug a Google app script?

Run a script in debug mode To run the script in debug mode, at the top of the editor click Debug. Before the script runs the line with the breakpoint it pauses and displays a table of debug information.


Video Answer


2 Answers

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.

like image 58
Jpsy Avatar answered Oct 18 '22 15:10

Jpsy


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).

like image 44
AdamL Avatar answered Oct 18 '22 16:10

AdamL