Google Sheet Script Logger New Log: Setup and Troubleshooting Guide

Author

Reads 745

Monitor of convenient modern computer in office
Credit: pexels.com, Monitor of convenient modern computer in office

Setting up a Google Sheet Script Logger New Log is a straightforward process. You'll need to install the Script Logger Add-on from the Google Workspace Marketplace.

The add-on allows you to log script executions, providing valuable insights into your script's behavior.

To enable logging, navigate to the Script Editor, click on the "Add-ons" menu, and select "Script Logger". Then, click on the "Enable" button.

Make sure to configure the logging settings to suit your needs.

Setting Up and Troubleshooting

To set up the Google Sheet Script Logger, you can either use the Apps Script library or copy and paste the Code.gs file directly into your script project. To use the library, go to "Resources > Libraries..." and enter the project key MYB7yzedMbnJaMKECt6Sm7FLDhaBgl_dE (or 1DSyxam1ceq72bMHsE6aOVeOl94X78WCwiYPytKi7chlg4x5GqiNXSw0l) and click "Select".

You can also choose a version from the dropdown box, usually the latest one, and click "Save". If you prefer to copy and paste the Code.gs file, make sure you have good error handling to catch and log stack traces.

If you're having trouble, it might be because you're calling the log method without enough arguments, like Logger.log("Test 1 2 %s"), which will cause an error. To avoid this, make sure to provide all the necessary arguments, like Logger.log("Test 1 2 %s", "three").

Take a look at this: How Do I Logout of Google Drive

Setup

A minimalist workspace setup featuring a cup, notebook, pen, and smartphone on a wooden desk indoors.
Credit: pexels.com, A minimalist workspace setup featuring a cup, notebook, pen, and smartphone on a wooden desk indoors.

To set up the LocalLogger, you can either use the Apps Script Editor or include the library in your project.

You can easily add the library to your script by clicking on the menu item "Resources > Libraries..." and searching for the project key MYB7yzedMbnJaMKECt6Sm7FLDhaBgl_dE.

Alternatively, you can copy and paste the Code.gs file directly into your script project. This will give you access to the LocalLogger's functionality.

To add the library, you'll need to choose a version from the dropdown box and click the "Save" button.

Consider reading: Data Transfer Project

Troubleshooting

Troubleshooting can be frustrating, but often it's a simple fix.

Calling the log method without enough arguments can cause an error. This happened when the code Logger.log("Test 1 2 %s") was run, but adding an extra argument like "three" fixed the issue.

You may need to run a function in the IDE to provoke script authorization. This is a common step to resolve the issue.

You might enjoy: Nexus S

LocalLogger Features and Usage

Credit: youtube.com, How to write Google Apps Script logs into Google Sheets

LocalLogger offers a range of features that make it a powerful tool for logging in Google Sheets. Optional Custom Sheet for Logging allows you to create a dedicated sheet for logging, while Configurable Logging Levels enable you to control the level of detail in your logs.

One of the key features of LocalLogger is its ability to send customizable email notifications. With Severity-Based Color Coding, you can categorize log messages by severity level and view them in a color-coded format. User Information in Logs provides valuable context to your log messages.

Here are the key features of LocalLogger:

  • Optional Custom Sheet for Logging
  • Configurable Logging Levels
  • Customizable Email Notifications
  • Dynamic Log Placement
  • Severity-Based Color Coding
  • User Information in Logs
  • Automated Log Sheet Setup

LocalLogger for Better Logging

LocalLogger ensures that logs are easily accessible within a Google Sheet, providing a persistent and organized record of script activity.

This is especially beneficial for scripts that are frequently executed or shared across teams, as it allows for immediate access to logs without navigating away from the workspace.

To set up LocalLogger, you'll need to create a new Google Sheet and go to the Apps Script Editor, where you can create a new file called LocalLogger and paste the implementation.

Additional reading: Newrelic Logging

Close-up action shot of a logger using a chainsaw to cut wood outdoors.
Credit: pexels.com, Close-up action shot of a logger using a chainsaw to cut wood outdoors.

LocalLogger's instantiation involves defining the email address the logs should be sent to, whether the newest log message should be placed in the first or last row of the sheet, the minimum severity level that should trigger an email notification, and the spreadsheet where the logs should be stored.

Here's a breakdown of the instantiation parameters:

  • Email address: If null, no emails will be sent.
  • New log placement: Whether the newest log message should be placed in the first or last row of the sheet.
  • Minimum severity level: The minimum severity level that should trigger an email notification.
  • Spreadsheet: The spreadsheet where the logs should be stored, which can be left blank if already working within a Google Sheet.

In the onOpen() function of the Sheet, you'll initialize the logger by calling the init() function, which checks for an existing 'Logs' sheet and creates one if necessary, complete with headers for 'Timestamp', 'Severity', 'Message', and 'User/Session'.

LocalLogger is a custom class that extends the basic logging functionality in Google Apps Script, allowing developers to log messages directly into a Google Sheet, categorizing them by severity levels for better clarity.

It includes a notification system sending email alerts in case of errors or critical issues.

Here are the key features of LocalLogger:

  • Optional Custom Sheet for Logging
  • Configurable Logging Levels
  • Customizable Email Notifications
  • Dynamic Log Placement
  • Severity-Based Color Coding
  • User Information in Logs
  • Automated Log Sheet Setup

Gbox420 Logs Tab

The Gbox420 Logs Tab is a crucial feature for monitoring your ESP8266 setup. It's where you'll find a record of all the logs generated by your ESP-link firmware.

Flat Screen Computer Monitor
Credit: pexels.com, Flat Screen Computer Monitor

To update the Logs.html page, you'll need to paste the URL generated from Google Sheets into the iframe section's src property. This URL should have been created during the "Publish to the web" step.

Once you've saved the file, re-upload all three HTML files to the ESP-link's web server. This will ensure your Logs Tab is up and running smoothly.

If this caught your attention, see: Google Website Url

Publishing and Testing

To publish your Google Sheet script logger, you'll need to deploy it as a web app. This will make it accessible from a shareable link.

You can then test it by visiting the link and verifying that it's working as expected. The script should log any new log messages to the specified log file.

Remember to update the script's permissions to include the "Anyone, even anonymous" setting, so that anyone can access the web app.

Publish to Web

Publishing to the web is a crucial step in making your spreadsheet accessible over the internet. This allows you to share it with others and access it from any device with an internet connection.

A tranquil forest scene showcases neatly stacked logs alongside a muddy path under sunlight.
Credit: pexels.com, A tranquil forest scene showcases neatly stacked logs alongside a muddy path under sunlight.

To publish your spreadsheet to the web, you need to use Google Sheets' "Publish to the web" feature. This will give you a URL that you can share with others.

You can also use a free URL shortening service like Bitly to create a custom short link for your published spreadsheet. This makes it easier to remember and share the link.

See what others are reading: Ad Url Google

Test Report to Sketch

To send a test report to Sketch, you'll need to follow a specific process. The expected output is that the report gets sent out from the Main module and processed by the Apps Script in the Google Sheets - GrowBoxLog sheet.

Make sure to URL encode special characters if you're passing text that contains them, as this can cause issues. You can use a tool like https://meyerweb.com/eric/tools/dencoder/ to encode or decode text.

To enable additional debug messages while the Google Apps Script processes the received report, go to the GrowBoxLog sheet - Settings tab and check the box to enable this feature.

Logs and Error Handling

Credit: youtube.com, How to Fix JSON API Script Issues in Google Sheets for Duplicate IDs and Error Handling?

Exception logging is a useful feature that sends unhandled exceptions in your script project code to Cloud Logging, along with a stack trace.

To view exception logs, follow these steps:

  1. Open the Apps Script project.
  2. At the left, click Executionsplaylist_play.
  3. At the top, click Add a filter > Status.
  4. Select the Failed and Timed out checkboxes.

You can also view logged exceptions in the GCP console if your script project is using a standard Google Cloud project that you have access to.

Execution Log

The execution log is a basic approach to logging in Apps Script. It's located at the top of the editor, and you can view it by clicking Execution log.

You can use either the Logger or console logging services in the execution log. These logs are intended for simple checks during development and debugging, and they don't persist very long.

Running a function or using the debugger will stream logs in real time into the execution log. For example, if you run a script with inputs "2" and "[email protected]", the logs will show something like this: [16-09-12 13:50:42:193 PDT] Emailing data row 2 to [email protected].

You can log strings, formatted strings, and even JSON objects using the functions provided by the Apps Script console service.

Curious to learn more? Check out: Support Google Com Refused to Connect

Exception Logging

Credit: youtube.com, How to Catch Exceptions, Format Logger's Time and Write a Log in Python - Python Logger Tutorial

Exception logging is a crucial aspect of logs and error handling. It sends unhandled exceptions in your script project code to Cloud Logging, along with a stack trace.

To view exception logs, you'll need to follow these steps:

  1. Open the Apps Script project.
  2. At the left, click Executionsplaylist_play.
  3. At the top, click Add a filter > Status.
  4. Select the Failed and Timed out checkboxes.

Alternatively, you can view logged exceptions in the GCP console if your script project is using a standard Google Cloud project that you have access to.

Patricia Dach

Junior Copy Editor

Patricia Dach is a meticulous and detail-oriented Copy Editor with a passion for refining written content. With a keen eye for grammar and syntax, she ensures that articles are polished and error-free. Her expertise spans a range of topics, from technology to lifestyle, and she is well-versed in various style guides.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.