Toggle menu

End Point Trace and Log

End point tracing and logging let you write information that is visible in the API Server console. Both are part of the End Point this object.

this.trace

this.trace( anything [, anything] )

Trace provides a basic trace mechanism. It accepts any number of parameters of any type.

For example:

function( params, credentials ) {
    let myVariable = "myValue";
    let myObject = {"key": "value"};
    this.trace("string");
    this.trace(myVariable);
    this.trace(myObject);
}

Would result in this being visible in the console:

End Point Trace
 

this.log

this.log( message [, object, customLogfile] )

The log function is more powerful than trace and should generally be used in preference to it. As well as being able to capture "anything", you are also able to set the error level, add extra information to the details pop-up (when you press the cog icon in the trace display), and, more usefully, write your logging to a dedicated log file.

For example:

function( params, credentials ) {
    let myVariable = "myValue";
    this.logError("Some text to log",{"myVariable": myVariable}, "myNewLogFile");
}

Would log this to the console's trace display:

End Point Log
 

Clicking the cog icon displays more details. Our object has been added to the existing default properties.

End Point Log Details
 

Log Files

The logs section of the console includes our new log file, which can be downloaded by clicking on it.

End Point Log File
 

The log file will be created automatically if one with your chosen name doesn't already exist. Further log entries will be written to the same file. For example, the content of myNewLogFile after the End Point above has been invoked three times might be:

["2017-09-06","11:01:20.404","error","Some text to log",{"myVariable":"myValue","name":"ajaxlibrary_3"}]
["2017-09-06","11:10:14.106","error","Some text to log",{"myVariable":"myValue","name":"ajaxlibrary_3"}]
["2017-09-06","11:10:31.494","error","Some text to log",{"myVariable":"anotherValue","name":"ajaxlibrary_3"}]

Log Error Levels

Log includes three standard levels, which are displayed by default in the trace view of the console and included in any log file. Note how log and logInfo are equivalent.

function( params, credentials ) {
    this.log("Some text to log");
    this.logInfo("Some text to log");
    this.logWarn("Some text to log");
    this.logError("Some text to log");
}

End Point Logging Levels
 

Returning Errors from Scheduled End Points

End points set to run using Scheduled Tasks can write errors to the scheduled task logs.

To log an error, throw a new error:

function(params, credentials) {
    throw new Error("Here's the error message");
}

This will add an entry to the Task Log:

Scheduled Task Log
 

Last modified on September 26, 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon