1

I have been attempting to find a method to log any errors that occur after a doPost(e) method executes with Apps Script (using JS). The previously answered question regarding this topic mentioned StackDriver logging with reference to the old editor provided by Google. However, how do I access a similar function with the new editor?

For some more context, if I execute functions from script editor, the Google Sheet they are editing, or through a trigger, I am able to view the errors through the Execution Log tab. But for any calls made through doPost, I am unable to view the causes of error. How do I log these errors?

Edit: I believe there might be a slight misunderstanding. The programmed doPost(e) takes user input from a Telegram bot and responds accordingly. Till date, the bot has been functioning as designed; however, for future debugging I wish to be able to somehow see any caused errors. This would provide more information than simply a "Failed" in the execution log. Any help is appreciated.

  • Why are you using JS to log errors from a doPost(e)? doPost(e) is a server side endpoint. How about just doing `Logger.log(JSON.stringify(e))` on the very first line after the function declaration. – Cooper Jun 10 '21 at 16:22
  • Executing the doPost(e) from a script editor is a bad idea unless you are providing the event object and I'm guessing since you're asking this question that you not providing the event object so it's a rather pointless exercise. – Cooper Jun 10 '21 at 16:24
  • @Cooper Ok I believe there might be room for some more clarity here. Currently, the doPost(e) collects its data based on user input to a Telegram bot. However, when errors occur with the doPost(e) after being called from Telegram, and because it is a server side endpoint and error logging, I am unable to diagnose the issue myself. As such, I'm trying to find a way to log these errors to work out why the error is occurring (for reference, it isn't a usual error, it occurs intermittently from time to time). – Vertigo Stalker Jun 10 '21 at 16:42
  • To keep it short, I'm trying to find a good way to debug an issue and get some actual information on the code rather than just knowing it failed. – Vertigo Stalker Jun 10 '21 at 16:44
  • You say `and because it is a server side endpoint and error logging, I am unable to diagnose the issue myself.` why not? – Cooper Jun 10 '21 at 16:48
  • And that is the part I am unaware of why I can't view them. I had previously tried a try-catch with both console.log and Logger.log (accompanied with a deliberate error from the bot), but neither showed any errors under Cloud Logs (yet the execution was still listed as failed). – Vertigo Stalker Jun 10 '21 at 16:55
  • I'm trying to learn here myself haha. I'm not too used to working with JS, let alone Apps Scripts. So thank you for taking the time to help! Hopefully, I can understand and work it out. – Vertigo Stalker Jun 10 '21 at 16:56
  • Have you looked in executions? – Cooper Jun 10 '21 at 17:00

1 Answers1

1

Apps Script Logging

Note:

Error Reporting interface in the Developer Console is pretty much similar with option 2 so I will not provide any further example.


Sample WebApp Code:

function doGet(e) {
  var params = JSON.stringify(e);
  console.log(params);
}

Sample Request:

https://script.google.com/..../exec?username=sample2&password=1234

Option1: Check the built-in Apps Script execution log

  1. You can check the logs when you open your script and go to Execution tab

enter image description here

  1. You can also check the logs in https://script.google.com/home/executions

enter image description here

Option2: Using Cloud Logging interface in the Developer Console

  • Assuiming you already attached a standard GCP project with your script project

You can view Cloud logs and error reports in the Google Cloud Platform console

  • Under Log Fields -> Select Apps Script Function
  • It will display the results under Query Results Tab

enter image description here

Ron M
  • 5,791
  • 1
  • 4
  • 16