A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/apps-script/reference/base/logger below:

Class Logger | Apps Script

Class Logger

Stay organized with collections Save and categorize content based on your preferences.

Logger

This class allows the developer to write to the Execution log and to Google Cloud Logging if the script is associated with a standard Cloud Project. This class is preferred for structured logging and jsonPayload support in Cloud Logging. For time-based logging, use console.

Methods Method Return type Brief description clear() void Clears the log. getLog() String Returns a complete list of messages in the current log. log(data) Logger Writes the data to the log. log(format, values) Logger Writes a formatted string to the logging console, using the format and values provided. Detailed documentation getLog()

Returns a complete list of messages in the current log. This method can be used to save or email the entire log output generated during script execution.

// Generate a log, then email it to the person who ran the script.
const files = DriveApp.getFiles();
while (files.hasNext()) {
  Logger.log(files.next().getName());
}
const recipient = Session.getActiveUser().getEmail();
const subject = 'A list of files in your Google Drive';
const body = Logger.getLog();
MailApp.sendEmail(recipient, subject, body);
Return

String — the log from the logging console

log(data)

Writes the data to the log. The data can be a string, a JavaScript object, or an object with a message property.

Logger.log("my log message");
// Info   my logmessage
Logger.log({ key: "value" });
// Info   {key=value}
Logger.log({ message: "my log message", data: { key: "value" } })
// Info   my logmessage

When passing an object, if the object contains a message property, that property is used as the log message. Otherwise, the toString() method is called to convert the object to a string. All other properties which are JSON serializable are included as part of the jsonPayload in the LogEntry, similar to the example below:

{
  "insertId": "w5eib...",
  "jsonPayload": {
    "message": "my log message",
    "serviceContext": {
      "service": "AKfyc..."
    },
    "data": {
      "key": "value"
    }
  },
  "resource": {
    "type": "app_script_function",
    "labels": {
      "invocation_type": "editor",
      "function_name": "unknown",
      "project_id": "1234567890"
    }
  },
  "timestamp": "2024-11-15T23:28:19.448591Z",
  "severity": "INFO",
  "labels": {
    "script.googleapis.com/user_key": "AOX2d...",
    "script.googleapis.com/process_id": "EAEA1...",
    "script.googleapis.com/project_key": "MQXvl...",
    "script.googleapis.com/deployment_id": "AKfyc..."
  },
  "logName": "projects/[PROJECT_ID]/logs/script.googleapis.com%2Fconsole_logs",
  "receiveTimestamp": "2024-11-15T23:28:20.363790313Z"
}
Parameters Name Type Description data Object the object to log Return

Logger — the Logger, for chaining.

log(format, values)

Writes a formatted string to the logging console, using the format and values provided. The string can include multiple %s placeholders, which are replaced with corresponding values from the list of arguments, converted to strings.

// Log the number of Google Groups you belong to.
const groups = GroupsApp.getGroups();
Logger.log('You are a member of %s Google Groups.', groups.length);
Parameters Name Type Description format String a format string that contains as many instances of %s as the number of values arguments values Object... a variable number of values to insert into the format string Return

Logger — the Logger, for chaining

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-12-02 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["The `Logger` class enables developers to write text to debugging logs for script analysis and troubleshooting."],["It provides methods to clear the log, retrieve the entire log as a string, and write formatted or unformatted messages to the log."],["Logged output can be viewed within the Apps Script editor using \"View \u003e Show logs\" and utilized for debugging purposes."],["The `getLog()` method allows for capturing the log content, which can then be used for saving, emailing, or further processing."],["Developers can leverage format strings and values to create structured log messages using the `log(format, values)` method."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4