I have a script that takes input from a JDBC connection and writes it to a worksheet. There are times that the result of this operation is not what was expected, so I have spread code like this at key points in the script:
Logger.log("Trying to delete rows, received: "
+ e.message) ;
Logger.log(" Continuing.") ;
When I run such code from the script editor's RUN button, I can see the latest execution log without effort - it's right there in front of me. But when I run the same code from a menu created like this:
function onOpen() {
var menuItems ;
var spreadsheet = SpreadsheetApp.getActive();
var user = Session.getEffectiveUser().getEmail() ;
var validUsers = [ validUsersList ]
if (spreadsheet.getDataRange().canEdit()) {
menuItems = [
{name: 'Process all streams' , functionName: 'processAllStreams'}
, {name: 'Build covered artists' , functionName: 'rebuildCoversSheet'}
//, {name: 'Add to song list' , functionName: 'buildSongList'}
//, {name: 'Process selective streams' , functionName: 'processStreams'}
//, {name: 'Move suggestions to top' , functionName: 'moveSuggestionsToTop'}
, {name: 'Go to bottom' , functionName: 'showBottomRange'}
, {name: 'New livestream details' , functionName: 'getNewLivestreamDetails'}
];
spreadsheet.addMenu('Process it', menuItems);
etc.
When run from that menu, I do not see the log. I have gone to the editor and checked there; it does not seem to know about scripts that were run outside of the development environment.
What must I do in order to see these logs? I realize that there is a cloud logging option but it looks like it's not such simple setup. And the docs don't say anything about limitations of running scripts via menu or via the script editor. The documentation does mention some limitations:
These logs are intended for simple checks during development and debugging, and do not persist very long.
But they don't seem to address this question. Are there easy approaches?
By the way, running from script editor is not an option for some of the things being done. The reason is that there are prompts and dialogs (getUi.prompt() etc) involved, and those are not allowed from Script Editor mode. So at present it's a catch 22.
EDIT - added a testable script
The following code:
function onOpen() {
var menuItems = [
{ name: 'Make a log entry', functionName: 'makeEntry' }
];
SpreadsheetApp.getActive().addMenu('Process it', menuItems);
}
function makeEntry() {
Logger.log('here you go....') ;
}
If you create a new Google Sheet and add this code into the script editor:
Running the script from the script editor, you will see the log entry that gets created.
Running the script from the created ("Process it") menu, I can find no way to find that log entry.
As I mentioned in the comments, you are running the function programmatically with Custom Menu that is why it's not appearing at the upper right execution log.
If you run the function manually, you can access the execution log
in the upper right of the App Script.
Since you are running the function programmatically using Custom Menu
, the execution log history can be accessed on the left side of the App Script.
The onOpen() trigger automatically runs when a user opens a spreadsheet, document, or presentation, and is typically used to add custom menu options to these Google Workspace apps (as well as Forms).