Logger log cleared automatically

2019-09-21 15:16发布

I created this script to send logs by email, similar to the example on https://developers.google.com/apps-script/reference/base/logger# A "Report problem" menu item is available to the users. However, seems like everytime a menu item is executed the log is cleared. Is there a way around this? If not, what is the purpose of having a logging system if it is cleared everytime a function is ran?

1条回答
一夜七次
2楼-- · 2019-09-21 15:25

The log is for debugging purposes. The idea is that once you run the function you are already in the script editor and you can just look at what went wrong.

To get around this, you can have the script that you are logging use getLog() to retrieve it as string and output the string into a file on the users Google Drive. YOur "Report Problem" script then takes that file and sends it over.

This is the way logs work in every programming language that I know. It is discarded and started from scratch when you start the program again unless you write it to a file. That is exactly what you have to do here as well.

EDIT: you can also view historical logs here: https://console.cloud.google.com under StackDriver → Logging → Logs

查看更多
登录 后发表回答