Class console

console

This class allows the developer to write to the Execution log and toGoogle Cloud Logging if the script is associated withastandardCloud Project.

For full support of Cloud Logging and structured logging, useLogger. Theconsole methodsserialize the objects to strings and do not supportjsonPayload as part of the structuredloggingLogEntry.

functionmeasuringExecutionTime(){constlabel="myFunction() time";// Labels the timing log entry.console.time(label);// Starts the timer.try{myFunction();// Function to time.}catch(e){// Logs an ERROR message.console.error("myFunction() yielded an error: "+e);}console.timeEnd(label);// Stops the timer, logs execution duration.}functionmyFunction(){// ...}

Methods

MethodReturn typeBrief description
error()voidOutputs a blank ERROR level message to Stackdriver Logging.
error(formatOrObject, values)voidOutputs an ERROR level message to Stackdriver Logging.
info()voidOutputs blank INFO level message to Stackdriver Logging.
info(formatOrObject, values)voidOutputs an INFO level message to Stackdriver Logging.
log()voidOutputs a blank DEBUG level message to Stackdriver Logging.
log(formatOrObject, values)voidOutputs a DEBUG level message to Stackdriver Logging.
time(label)voidStarts a timer you can use to track how long an operation takes.
timeEnd(label)voidStops a timer that was previously started by callingconsole.time().
warn()voidOutputs a blank WARNING level message to Stackdriver Logging.
warn(formatOrObject, values)voidOutputs a WARNING level message to Stackdriver Logging.

Detailed documentation

error()

Outputs a blank ERROR level message to Stackdriver Logging.


error(formatOrObject, values)

Outputs an ERROR level message to Stackdriver Logging.

Parameters

NameTypeDescription
formatOrObjectObjecta string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters.
valuesObject...objects with which to replace substitution strings within the message. This gives you additional control over the format of the output.

info()

Outputs blank INFO level message to Stackdriver Logging.


info(formatOrObject, values)

Outputs an INFO level message to Stackdriver Logging.

Parameters

NameTypeDescription
formatOrObjectObjecta string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters.
valuesObject...objects with which to replace substitution strings within the message. This gives you additional control over the format of the output.

log()

Outputs a blank DEBUG level message to Stackdriver Logging.


log(formatOrObject, values)

Outputs a DEBUG level message to Stackdriver Logging.

Parameters

NameTypeDescription
formatOrObjectObjecta string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters.
valuesObject...objects with which to replace substitution strings within the message. This gives you additional control over the format of the output.

time(label)

Starts a timer you can use to track how long an operation takes.

Parameters

NameTypeDescription
labelStringThe name to give the new timer.

timeEnd(label)

Stops a timer that was previously started by callingconsole.time(). The time durationis logged in Stackdriver.

Parameters

NameTypeDescription
labelStringthe name of the timer to stop.

warn()

Outputs a blank WARNING level message to Stackdriver Logging.


warn(formatOrObject, values)

Outputs a WARNING level message to Stackdriver Logging.

Parameters

NameTypeDescription
formatOrObjectObjecta string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters.
valuesObject...objects with which to replace substitution strings within the message. This gives you additional control over the format of the output.

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 2024-12-02 UTC.