Unable to get console.log or Logger.log to actually log anything

27 views
Skip to first unread message

Michael Haws

unread,
Nov 24, 2025, 3:58:08 AM (6 days ago) Nov 24
to Google Apps Script Community
The script executes properly and populates my spreadsheet but nothing ever shows in the execution log files ...   here is my script ...

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
Logger.log("hello");
console.log("hello1");
function doPost(e) {
try {
const jsonData = JSON.parse(e.postData.contents);
const column = jsonData.column;
const elapsedTime = jsonData.elapsedtime;
const solution = jsonData.solution;
const lastRow = sheet.getLastRow();
const firstRow = 6;

Logger.log(column);
Logger.log(elapsedTime);
Logger.log(solution);
var found = 0;
for (var row = firstRow ; row <= lastRow ; row++) {
if (solution == sheet.getRange(row,1).getValue()) {
found = 1;
break;
}
}
if (found) {
sheet.getRange(row,column).setValue(elapsedTime);
} else {
sheet.insertRows(6);
var range = sheet.getRange(6,1);
range.setFontColor('white');
range.setValue(solution);
sheet.getRange(6,column).setValue(elapsedTime);
}
return ContentService.createTextOutput(JSON.stringify({ status:"success",message: "Data received and processed." })).setMimeType(ContentService.MimeType.JSON);

} catch (error) {
Logger.log(error.message);
return ContentService.createTextOutput(JSON.stringify({ status:"error",message: error.message })).setMimeType(ContentService.MimeType.JSON);

}

-RAGHZ- Plays

unread,
Nov 27, 2025, 7:07:38 PM (2 days ago) Nov 27
to Google Apps Script Community
The issue is that Logger.log() and console.log() don't work in doPost() functions (or any web app functions triggered by external requests). This is because those functions run in a different execution context and their logs aren't accessible through the normal Apps Script interface.  

A few fixes are:

Solution 1: Log to the Spreadsheet (Create a dedicated logging sheet to see what's happening)
Solution 2: Use Stackdriver Logging (Google Cloud Logging)  
Solution 3: Return Debug Info in Response

Easiest is solution 1 in my opinion, I can implement it into your script and send it to you here or if you wish to attempt it. Feel free to let me know!  

Michael Haws

unread,
Nov 27, 2025, 7:16:49 PM (2 days ago) Nov 27
to google-apps-sc...@googlegroups.com
Solution 1 looks like a great idea,  thank you so much!!!

Michael

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/b90dbaf7-3d76-40a3-b191-161295ba7fean%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages