Class console

console

This class allows the developer to write logs to the Google Cloud Platform's Stackdriver Logging service. The following shows some logging examples:

 function 
  
 measuringExecutionTime 
 () 
  
 { 
  
 // 
  
 A 
  
 simple 
  
 INFO 
  
 log 
  
 message 
 , 
  
 using 
  
 sprintf 
 () 
  
 formatting 
 . 
  
 console 
 . 
 info 
 ( 
 'Timing the 
 %s 
 function ( 
 %d 
 arguments)' 
 , 
  
 'myFunction' 
 , 
  
 1 
 ); 
  
 // 
  
 Log 
  
 a 
  
 JSON 
  
 object 
  
 at 
  
 a 
  
 DEBUG 
  
 level 
 . 
  
 If 
  
 the 
  
 object 
  
 contains 
  
 a 
  
 property 
  
 called 
  
 "message" 
 , 
  
 // 
  
 that 
  
 is 
  
 used 
  
 as 
  
 the 
  
 summary 
  
 in 
  
 the 
  
 log 
  
 viewer 
 , 
  
 otherwise 
  
 a 
  
 stringified 
  
 version 
  
 of 
  
 // 
  
 the 
  
 object 
  
 is 
  
 used 
  
 as 
  
 the 
  
 summary 
 . 
  
 var 
  
 parameters 
  
 = 
  
 { 
  
 isValid 
 : 
  
 true 
 , 
  
 content 
 : 
  
 'some string' 
 , 
  
 timestamp 
 : 
  
 new 
  
 Date 
 () 
  
 }; 
  
 console 
 . 
 log 
 ( 
 parameters 
 ); 
  
 var 
  
 label 
  
 = 
  
 '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() yielded an error: ' 
  
 + 
  
 e 
 ); 
  
 } 
  
 console 
 . 
 timeEnd 
 ( 
 label 
 ); 
  
 // 
  
 Stops 
  
 the 
  
 timer 
 , 
  
 logs 
  
 execution 
  
 duration 
 . 
 } 

Methods

Method Return type Brief description
void Outputs a blank ERROR level message to Stackdriver Logging.
void Outputs an ERROR level message to Stackdriver Logging.
void Outputs blank INFO level message to Stackdriver Logging.
void Outputs an INFO level message to Stackdriver Logging.
void Outputs a blank DEBUG level message to Stackdriver Logging.
void Outputs a DEBUG level message to Stackdriver Logging.
void Starts a timer you can use to track how long an operation takes.
void Stops a timer that was previously started by calling console.time() .
void Outputs a blank WARNING level message to Stackdriver Logging.
void Outputs 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

Name Type Description
formatOrObject
Object a string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters.
values
Object... 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

Name Type Description
formatOrObject
Object a string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters.
values
Object... 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

Name Type Description
formatOrObject
Object a string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters.
values
Object... 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

Name Type Description
label
String The name to give the new timer.

timeEnd(label)

Stops a timer that was previously started by calling console.time() . The time duration is logged in Stackdriver.

Parameters

Name Type Description
label
String the 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

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