First Steps with Google Workspace Studio: AI Workflow Development Course Connecting Gmail, Calendar and Spreadsheets

Your Primary Tool: How to Read and Interpret Execution Logs Effectively

While the principles of systematic debugging from classics like Code Complete and The Pragmatic Programmer provide a timeless foundation, applying them requires a concrete starting point. When your Google Workspace workflow mysteriously fails—a calendar event isn't created, a spreadsheet cell remains empty, an email refuses to send—your first instinct might be frustration. But the solution isn't to guess; it's to look at the evidence. This brings us to the single most important, yet often overlooked, tool in your Apps Script arsenal: the Execution Log.

Think of the Execution Log as a black box flight recorder for your code. It’s an unchangeable, chronological account of what your script actually did, not what you hoped it would do. Learning to read and interpret these logs effectively is the foundational skill that separates struggling beginners from proficient workflow developers. It transforms a cryptic error message from a dead end into a breadcrumb trail leading directly to the source of the problem.

So, where do you find this crucial tool? Within the Apps Script editor for your project, look for the clock icon labeled "Executions" in the left-hand sidebar. Clicking this will show you a history of every time your script has run, whether it was triggered manually, by a timer, or by an event like a form submission. Each entry shows a start time, duration, and status (like "Completed" or "Failed"). Clicking on a specific execution opens up the detailed log for that run.

At first glance, the log can seem like a jumble of timestamps and technical jargon. Let’s break down a simple, successful execution. Imagine a script designed to pull a client's name from a spreadsheet.

function processClientData() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Client List");
  const clientName = sheet.getRange("B2").getValue();
  
  Logger.log("Accessing sheet: Client List");
  console.log("Retrieved client name: " + clientName);
  
  // ... more code to process the data
}

The execution log for this would show a clean, step-by-step story. You'd see entries corresponding to your Logger.log() and console.log() statements, confirming that the sheet was accessed and the name was retrieved. It tells you, "Everything went according to plan." This is your baseline for what a healthy execution looks like.

But the real power of logs shines when things go wrong. Let's introduce a common, simple mistake. Suppose a colleague renames the spreadsheet tab from "Client List" to "Clients" without telling you. The next time the script runs, it fails.

// This script will fail because the sheet name is wrong.
function processClientData() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Client List");
  // On the line below, 'sheet' is null, so calling .getRange() on it will cause an error.
  const clientName = sheet.getRange("B2").getValue();

  Logger.log("This message will never be logged.");
}

When you check the logs for this failed execution, you won't see your final log message. Instead, you'll see a red, alarming-looking error entry. It will likely say something like: TypeError: Cannot read properties of null (reading 'getRange').

チャプターへ戻る