Debugging Apps Script: Logger, console.log, and the Execution Log

When your Apps Script doesn't behave as expected, knowing how to inspect what's happening is the difference between a 5-minute fix and an hour of guessing. Here's everything you need to debug effectively.

Logger.log() — the classic approach

Logger.log() writes output to the Logs panel in the Apps Script editor. Open it with View > Logs (or Ctrl+Enter / Cmd+Enter).

function myFunction() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const value = sheet.getRange('A1').getValue(); Logger.log('Value in A1: %s', value); Logger.log('Type: %s', typeof value); }

Logger.log supports %s (string), %d (number), and %j (JSON) format specifiers.

Log an object

function logObject() { const data = { name: 'Alice', score: 95 }; Logger.log(JSON.stringify(data, null, 2)); }

console.log() — for Stackdriver / Cloud Logging

console.log() writes to Stackdriver Logging (now called Google Cloud Logging). It's useful when:

  • Your script runs from a trigger (where Logger.log output isn't easily accessible).
  • You need log history beyond the current session.
function triggerFriendlyLogging() { console.log('Script started'); console.info('Processing row:', 5); console.warn('Possible issue detected'); console.error('Something went wrong'); }

View these logs in the Apps Script editor under Executions, then click on a specific execution to see its logs.

The Execution Log

The Execution Log panel (bottom of the editor) shows real-time output while a script is running. It displays:

  • Logger.log output
  • Errors and stack traces
  • Execution duration

It's the fastest feedback loop when running scripts manually.

try/catch for graceful error handling

Wrap risky operations in try/catch to log errors without crashing the whole script:

function safeOperation() { try { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const value = sheet.getRange('Z999').getValue(); // Might be empty Logger.log('Got value: ' + value); } catch (error) { Logger.log('Error: ' + error.message); console.error('safeOperation failed:', error); } }

Log every row when processing data

When looping over rows, log progress so you know exactly where a failure occurred:

function processRows() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const data = sheet.getDataRange().getValues(); data.forEach((row, i) => { try { Logger.log(`Row ${i + 1}: ${JSON.stringify(row)}`); // ... your processing logic here } catch (e) { Logger.log(`Error on row ${i + 1}: ${e.message}`); } }); }

Viewing past execution logs

  1. Open your script in the Apps Script editor.
  2. Click Executions in the left sidebar.
  3. Select any past execution to see its logs, duration, and error details.

This is especially valuable for debugging trigger-based scripts that ran while you weren't watching.

Breakpoints and step-through debugging

The Apps Script editor supports basic breakpoints:

  1. Click in the gutter (left of the line number) to set a breakpoint.
  2. Use the Debug button (bug icon) instead of Run.
  3. Step through using the toolbar controls (Step Over, Step Into, etc.).
  4. Inspect variable values in the Variables panel on the left.

Quick reference

ToolBest for
Logger.log()Interactive runs, quick inspection
console.log()Trigger-based runs, persistent logs
Execution LogReal-time feedback during manual runs
BreakpointsStep-through debugging of complex logic
try/catchIsolating errors in loops or API calls