简体   繁体   中英

Logger.getLog() is not working: Google Apps Scripts

I wanted to view my log from the sheet front end, I tried following workaround but it seems getLog() function is not working.

// log adding function
function addLogs()
{
  Logger.log("Adding my test log");
}

// log display function
function viewLog()
{
  var logs = Logger.getLog(); // issue is here
  Browser.msgBox(logs); // gives empty
  var htmlOutput = HtmlService 
     .createHtmlOutput(logs)
     .setSandboxMode(HtmlService.SandboxMode.IFRAME).setHeight(500);
    SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Sheet Log'); // gives empty
} 

Try combining your functions together as a nested function. When you run the code, you have added to the log in one function, and called an empty log in the other.

You will either need to add to the log and call it in the same function or nest the functions together so that when you run the topmost function, it runs all processes.

Did you call the function addLogs() at all? It's not going to run on it's own and hence the log will be empty at the beginning. Correct behaviour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM