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).
Logger.log supports %s (string), %d (number), and %j (JSON) format specifiers.
Log an object
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.logoutput isn't easily accessible). - You need log history beyond the current session.
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.logoutput- 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:
Log every row when processing data
When looping over rows, log progress so you know exactly where a failure occurred:
Viewing past execution logs
- Open your script in the Apps Script editor.
- Click Executions in the left sidebar.
- 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:
- Click in the gutter (left of the line number) to set a breakpoint.
- Use the Debug button (bug icon) instead of Run.
- Step through using the toolbar controls (Step Over, Step Into, etc.).
- Inspect variable values in the Variables panel on the left.
Quick reference
| Tool | Best for |
|---|---|
Logger.log() | Interactive runs, quick inspection |
console.log() | Trigger-based runs, persistent logs |
| Execution Log | Real-time feedback during manual runs |
| Breakpoints | Step-through debugging of complex logic |
try/catch | Isolating errors in loops or API calls |