how to log apps-script with user interaction?

2019-07-26 22:02发布

问题:

I would like to log an apps-script that is meant to be run as a service, and requires user-interaction. The log journal (in google script editor) logs indeed the "doGet start" entry but not the "handler" one... as clicking on the "execute" button in the google editor does not show the UiApp.

The only way I found to effectively see the Ui is to publish the script and execute its public url... but then I don't know where to find the logs.

Any hint is welcome, thanks.

function doGet() {
  Logger.log("doGet start");
  var app = UiApp.createApplication().setTitle(" ");
  var handler = app.createServerHandler('selectionHandler');
  var docsUI = app.createDocsListDialog().addSelectionHandler(handler).showDocsPicker();
  return app;
}

function selectionHandler(e){
  var app = UiApp.getActiveApplication();
  Logger.log("handler");
  Logger.log(e.parameter);
  return app;
}

回答1:

There is an open issue - Issue 811 which asks for a persistent logger function. Please star it to add your vote. In the absence of this feature, you can write the logs to a Spreadsheet cell or a document in your Google Drive which you can see . You can use the Logger.getLog() function to get the entire text of your logger thus far



回答2:

To debug my web deployed applications, I wrote a library which adds a log window to applications and permits to output messages to this window. The Library's Project Key is MHDTOOt9dn-ViHNtwfsIfJ5lu8m0d5vP9. There is a demo showing the abilities. The source code is also available.

I hope it can help you to workaround the Logger service problems.



回答3:

There is also a more general issue about logger that was reported in july (since it used to work before that...) and I do hope Google will fix it since it's far more convenient than any other method to debug a script. You could vote for it too ;-)

In the meantime, Srik's suggestion is the only way I'm afraid...

EDIT : and, of course the utility library mentionned in the above post by Megabyte1024 which ils very helpfull and handy.