LoginSignup
1
1

More than 5 years have passed since last update.

GAS EventのDebug方法はLogで行う

Posted at

TL;DR

Logを入れ、調査するしかない。
ブレークポイントは張れなさそう

2種類のlog

Stackdriver Logging

Apps Script dashboardで見る。(https://script.google.com/home/executions)

console.log("checkmethod start");
var sample = "TarakoPasta is great food";
console.log(sample);
console.log("checkmethod start");

Basic Logging

Script EditorのView > Logsで見られる。Ctrl+Enterでも見られるのでこっちのが楽。

Logger.log("checkmethod start");
var sample = "TarakoPasta is great food";
Logger.log(sample);
Logger.log("checkmethod start");

事例

下準備

1.コードを下のように書く。

function onEdit(e){
  Logger.log("LoggerLog start");
  console.log("ConsoleLog start");

  today = new Date()
  Logger.log(today);
  console.log(today);

  Logger.log("Log End");  
  console.log("ConsoleLog End");
}

2.GoogleSpreadSheetでセルを編集する。

結果

Stackdriver logs


Stackdriver logs 
May 20, 2019, 5:21:44 PM DEBUG ConsoleLog start
May 20, 2019, 5:21:44 PM DEBUG Mon May 20 17:21:44 GMT+09:00 2019
May 20, 2019, 5:21:44 PM DEBUG ConsoleLog End

Basic Logging


[19-05-20 17:21:44:706 JST] LoggerLog start
[19-05-20 17:21:44:709 JST] Mon May 20 17:21:44 GMT+09:00 2019
[19-05-20 17:21:44:710 JST] Log End

参考資料

https://stackoverflow.com/questions/11539411/how-to-debug-google-apps-script-aka-where-does-logger-log-log-to
https://developers.google.com/apps-script/guides/logging#stackdriver_logging
https://developers.google.com/apps-script/guides/triggers/events

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1