Scriptdrill

Getting started Updated November 2026

Logger.log and console.log

Logger.log(value) and console.log(value) both write to the Execution log shown under the editor after a run; for trigger runs open Executions in the left panel and expand the run. Logger.log supports placeholders: Logger.log("%s has %s rows", name, n). Objects and 2D arrays are readable with JSON.stringify(value).

Syntax

Logger.log(value) | Logger.log(format, ...args) | console.log(value) | console.error(value)
PartWhat it is
%sPlaceholder replaced by the next argument in Logger.log
console.info / warn / errorSeverity levels shown with colors in Executions and Cloud Logging
console.time(label) / console.timeEnd(label)Measure how long a block takes

Examples

const sheet = SpreadsheetApp.getActiveSheet();
Logger.log("%s has %s rows", sheet.getName(), sheet.getLastRow());

Result: Orders has 120 rows

const data = sheet.getRange("A1:B2").getValues();
Logger.log(data);
Logger.log(JSON.stringify(data));

Result: [[Name, Qty], [Pens, 12.0]] then [["Name","Qty"],["Pens",12]]

try {
  SpreadsheetApp.openById("bad-id");
} catch (err) {
  console.error("Open failed: " + err.message);
}

Result: Open failed: Unexpected error while getting the method or property openById ... shown in red in Executions

Common mistakes

  • Nothing shows in the log: the function was run by a trigger, not the editor; open Executions in the left bar and click the run.
  • Logging an object prints [object Object]: use JSON.stringify(obj) or Logger.log(obj) without string concatenation.
  • Logger.log inside a custom function shows nothing: custom functions do not keep logs reliably; test the function from the editor with sample arguments.
  • Logs cut off after many lines: the editor log truncates long output; log counts and samples, not the entire sheet.

Practice Logger.log and console.log

These drills check your answer on live data, free, no account needed.

  • Align a text table`rows` is an array of rows, each an array of strings with the same number of cells. Return one line per row: pad every column to its widest cell, with the first column left-aligned and the other columns right-aligned, cells joined by two spaces, and no trailing spaces on any line.
  • Format a durationFormat a whole number of seconds like `"1d 2h 3m 4s"`, using days, hours, minutes and seconds, largest first. Leave out units that are zero. Zero seconds is `"0s"`.

Questions

Logger.log or console.log?

Both work in V8. console.log integrates with Cloud Logging and supports levels; Logger.log has the %s formatting. Pick one and be consistent.

How do I see logs from a trigger that ran last night?

Executions (the list icon on the left) shows every run with its status and duration; click a row to see its log lines.

Related

  • try, catch and finallyHandle errors in Google Apps Script with try catch finally: catch exceptions from sheets, email and APIs, read err.message and err.stack, log and rethrow.
  • Your first Apps ScriptWrite and run your first Google Apps Script in Sheets: open the editor, write a function that reads and writes cells, run it, authorize it and read the log.
  • JSON.parse and JSON.stringifyUse JSON.parse and JSON.stringify in Google Apps Script: turn an API response into objects, write nested fields to a sheet, store objects as properties.
  • getRange and getValuesRead Google Sheets data with Apps Script: getRange by A1 notation or row and column numbers, then getValue for one cell or getValues for a 2D array of rows.

Previous: PropertiesServiceNext: Utilities.formatDate