Logging Stay organized with collections Save and categorize content based on your preferences.
When developing any kind of app, you often want to log information to helpdiagnose faults during development, to identify and diagnose customer issues,and for other purposes.
Apps Script provides three different mechanisms for logging:
The built-inApps Script execution log.This log is lightweight and streams in real time, but persists only for ashort time.
TheCloud Logging interface in theDeveloper Console, which provides logs that persist for many days after theircreation.
TheError Reporting interfacein the Developer Console, which collects and records errors that occurwhile your script is running.
These are described in the following sections. In addition to these mechanisms,you can also build your own logger code that, for example, writes informationto a loggingSpreadsheetorJDBC database.
Use the Apps Script execution log
A basic approach to logging in Apps Script is to use the built-in execution log. To view these logs, at the top of the editor, clickExecution log. When you run a function or use the debugger, the logs stream in real time.
You can use either theLogger
orconsole
logging services in the built-in execution log.
These logs are intended for simple checks during development and debugging, and do not persist very long.
For example, consider this function:
/** * Logs Google Sheet information. * @param {number} rowNumber The spreadsheet row number. * @param {string} email The email to send with the row data. */functionemailDataRow(rowNumber,email){console.log('Emailingdatarow'+rowNumber+'to'+email);try{constsheet=SpreadsheetApp.getActiveSheet();constdata=sheet.getDataRange().getValues();constrowData=data[rowNumber-1].join('');console.log('Row'+rowNumber+'data:'+rowData);MailApp.sendEmail(email,'Datainrow'+rowNumber,rowData);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failedwitherror%s',err.message);}}
When this script is run with inputs "2" and "john@example.com" thefollowing logs are written:
[16-09-12 13:50:42:193 PDT] Emailing data row 2 to john@example.com
[16-09-12 13:50:42:271 PDT] Row 2 data: Cost 103.24
Cloud Logging
Apps Script also provides partial access to the Google Cloud Platform (GCP)Cloud Logging service. When yourequire logging that persists for several days, or need a more complex loggingsolution for a multi-user production environment, Cloud Logging is the preferredchoice. SeeCloud Logging quotas and limitsfor data retention and other quota details.
If you need more logging quota, you cansubmit a Google Cloud Platform quota request.This requires that you have access to theCloud Platform projectthat your script uses.
Note: Cloud Logging provides a number of services beyond storinglogs, such as alerts and metrics. At this time these services aren't availablefrom Apps Script.Using Cloud Logging
Cloud logs are attached to theGoogle Cloud projectassociated with your Apps Script. You can view a simplified version of theselogs in theApps Script dashboard.
To make full use of Cloud Logging and its capabilities, use astandard Google Cloud projectwith your script project. This lets you access Cloud logs directly in theGCP Consoleand gives you more viewing and filtering options.
Note: If you use the Rhino runtime, Cloud Logging doesn't support the AppsScriptLogger
service. Instead, use theconsole
service.When logging, it is good privacy practice to avoid recording any personalinformation about the user, such as email addresses. Cloud logs areautomatically labeled withactive user keysyou can use to locate a specific user's log messages when necessary.
You can log strings, formatted strings, and even JSON objects using thefunctions provided by the Apps Scriptconsole
service.
The following example shows how to use theconsole
service to log information in Cloud Operations.
/** * Logs the time taken to execute 'myFunction'. */functionmeasuringExecutionTime(){// A simple INFO log message, using sprintf() formatting.console.info('Timingthe%sfunction(%darguments)','myFunction',1);// Log a JSON object at a DEBUG level. The log is labeled// with the message string in the log viewer, and the JSON content// is displayed in the expanded log structure under "jsonPayload".constparameters={isValid:true,content:'somestring',timestamp:newDate()};console.log({message:'FunctionInput',initialData:parameters});constlabel='myFunction()time';// Labels the timing log entry.console.time(label);// Starts the timer.try{myFunction(parameters);// Function to time.}catch(e){// Logs an ERROR message.console.error('myFunction()yieldedanerror:'+e);}console.timeEnd(label);// Stops the timer, logs execution duration.}
Active user keys
Temporary active user keys provide a convenient way to spot unique users inCloud Log entries without revealing the identities of those users. Keysare per script and change roughly once a month to provide additional securityshould a user reveal their identity to a developer, for example while reportingan issue.
Temporary active user keys are superior to logging identifiers like emailaddresses because:
- You don't have to add anything to your logging; they're already there!
- They don't require user authorization.
- They protect user privacy.
To find temporary active user keys in your Cloud Log entries,view your Cloud logs in the Google Cloud console.You can do this only if your script project is using astandard Google Cloud projectthat you have access to. Once you've opened the Google Cloud project in the console,select a log entry of interest and expand it to viewmetadata > labels > script.googleapis.com/user_key.
You can also get the temporary active user key by callingSession.getTemporaryActiveUserKey()
in your script. One way to use this method is to display the key to the userwhile they are running your script. Then users may choose to include their keyswhen reporting issues to help you identify the relevant logs.
Exception logging
Exception logging sends unhandled exceptions in your script project codeto Cloud Logging, along with a stack trace.
To view exception logs, follow the steps below:
- Open the Apps Script project.
- At the left, clickExecutions .
- At the top, clickAdd a filter > Status.
- Select theFailed andTimed out checkboxes.
You can alsoview logged exceptions in the GCP consoleif your script project is using astandard Google Cloud projectthat you have access to.
Enable exception logging
Exception logging is enabled by default for new projects. To enable exceptionlogging for older projects, follow the steps below:
- Open the script project.
- At the left, clickProject Settings .
- Select theLog uncaught exceptions to Cloud Operations checkbox.
Error Reporting
Exception logging automatically integrates withCloud Error Reporting,a service that aggregates and displays errors produced in your script.You canview your Cloud error reports in the Google Cloud console.If you are prompted to "Set up Error Reporting" this is becauseyour script has not yet logged any exceptions. No setup is required beyondenabling exception logging.
Logging requirements
There are no requirements for using the built-in execution log.
You can view a simplified version of Cloud logs in theApps Script dashboard. However, tomake the most of Cloud Logging and error reporting you must have accessto the GCP project of the script. This is only possible if your script projectis using astandard Google Cloud project.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-04 UTC.