console

Description

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts

The console API provides program logging facilities.

Methods

Name Return Value Summary
assert None

Logs an "ERROR" message to the program log and triggers Script.errorMessage, if a test condition fails. The message logged is "ERROR - Assertion failed : " followed by the message values separated by spaces.

Note: Script execution continues whether or not the test condition fails.

clear None

Clears the Developer > Scripting > Script Log debug window.

debug None

Logs a message to the program log and triggers Script.printedMessage. The message logged is the message values separated by spaces.

error None

Logs an "ERROR" message to the program log and triggers Script.errorMessage. The message logged is "ERROR - " followed by the message values separated by spaces.

exception None

A synonym of console.error. Logs an "ERROR" message to the program log and triggers Script.errorMessage. The message logged is "ERROR - " followed by the message values separated by spaces.

group None

Logs a message to the program log and triggers Script.printedMessage, then starts indenting subsequent console.log messages until a console.groupEnd. Groups may be nested.

groupCollapsed None

Has the same behavior as console.group. Logs a message to the program log and triggers Script.printedMessage, then starts indenting subsequent console.log messages until a console.groupEnd. Groups may be nested.

groupEnd None

Finishes a group of indented console.log messages.

info None

Logs an "INFO" message to the program log and triggers Script.infoMessage. The message logged is "INFO -" followed by the message values separated by spaces.

log None

Logs a message to the program log and triggers Script.printedMessage. The message logged is the message values separated by spaces.

If a console.group is in effect, the message is indented by an amount proportional to the group level.

time None

Starts a timer, logs a message to the program log, and triggers Script.printedMessage. The message logged has the timer name and "Timer started".

timeEnd None

Finishes a timer, logs a message to the program log, and triggers Script.printedMessage. The message logged has the timer name and the number of milliseconds since the timer was started.

trace None

Logs the JavaScript call stack at the point of call to the program log.

warn None

Logs a "WARNING" message to the program log and triggers Script.warningMessage. The message logged is "WARNING - " followed by the message values separated by spaces.

Method Details

(static) assert( assertion, …messageopt )

Logs an "ERROR" message to the program log and triggers Script.errorMessage, if a test condition fails. The message logged is "ERROR - Assertion failed : " followed by the message values separated by spaces.

Note: Script execution continues whether or not the test condition fails.

Parameters

Name Type Attributes Description
assertion boolean

The test condition value.

message * <optional>
<repeatable>

The message values to log if the assertion evaluates to false.

Example

Demonstrate assertion behavior.

Script.errorMessage.connect(function (message, scriptName) {
    console.info("Error message logged:", "\"" + message + "\"", "in", "[" + scriptName + "]");
});

console.assert(5 === 5, "5 equals 5.", "This assertion will succeed.");  // No log output.
console.assert(5 > 6, "5 is not greater than 6.", "This assertion will fail.");  // Log output is generated.
console.info("Script continues running.");

// ERROR - Assertion failed :  5 is not greater than 6. This assertion will fail.
// INFO - Error message logged: "Assertion failed :  5 is not greater than 6. This assertion will fail." in [console.js]
// INFO - Script continues running.
(static) clear( )

Clears the Developer > Scripting > Script Log debug window.

(static) debug( …messageopt )

Logs a message to the program log and triggers Script.printedMessage. The message logged is the message values separated by spaces.

Parameters

Name Type Attributes Description
message * <optional>
<repeatable>

The message values to log.

(static) error( …messageopt )

Logs an "ERROR" message to the program log and triggers Script.errorMessage. The message logged is "ERROR - " followed by the message values separated by spaces.

Parameters

Name Type Attributes Description
message * <optional>
<repeatable>

The message values to log.

(static) exception( …messageopt )

A synonym of console.error. Logs an "ERROR" message to the program log and triggers Script.errorMessage. The message logged is "ERROR - " followed by the message values separated by spaces.

Parameters

Name Type Attributes Description
message * <optional>
<repeatable>

The message values to log.

(static) group( message )

Logs a message to the program log and triggers Script.printedMessage, then starts indenting subsequent console.log messages until a console.groupEnd. Groups may be nested.

Parameters

Name Type Description
message *

The message value to log.

Example

Nested groups.

console.group("Group 1");
console.log("Sentence 1");
console.log("Sentence 2");
console.group("Group 2");
console.log("Sentence 3");
console.log("Sentence 4");
console.groupEnd();
console.log("Sentence 5");
console.groupEnd();
console.log("Sentence 6");

//Group 1
//   Sentence 1
//   Sentence 2
//   Group 2
//      Sentence 3
//      Sentence 4
//   Sentence 5
//Sentence 6
(static) groupCollapsed( message )

Has the same behavior as console.group. Logs a message to the program log and triggers Script.printedMessage, then starts indenting subsequent console.log messages until a console.groupEnd. Groups may be nested.

Parameters

Name Type Description
message *

The message value to log.

(static) groupEnd( )

Finishes a group of indented console.log messages.

(static) info( …messageopt )

Logs an "INFO" message to the program log and triggers Script.infoMessage. The message logged is "INFO -" followed by the message values separated by spaces.

Parameters

Name Type Attributes Description
message * <optional>
<repeatable>

The message values to log.

(static) log( …messageopt )

Logs a message to the program log and triggers Script.printedMessage. The message logged is the message values separated by spaces.

If a console.group is in effect, the message is indented by an amount proportional to the group level.

Parameters

Name Type Attributes Description
message * <optional>
<repeatable>

The message values to log.

Example

Log some values.

Script.printedMessage.connect(function (message, scriptName) {
    console.info("Console.log message:", "\"" + message + "\"", "in", "[" + scriptName + "]");
});

console.log("string", 7, true);

// string 7 true
// INFO - Console.log message: "string 7 true" in [console.js]
(static) time( name )

Starts a timer, logs a message to the program log, and triggers Script.printedMessage. The message logged has the timer name and "Timer started".

Parameters

Name Type Description
name string

The name of the timer.

Example

Time some processing.

function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds) {
            break;
        }
    }
}

console.time("MyTimer");
sleep(1000);  // Do some processing.
console.timeEnd("MyTimer");

// MyTimer: Timer started
// MyTimer: 1001ms
(static) timeEnd( name )

Finishes a timer, logs a message to the program log, and triggers Script.printedMessage. The message logged has the timer name and the number of milliseconds since the timer was started.

Parameters

Name Type Description
name string

The name of the timer.

(static) trace( )

Logs the JavaScript call stack at the point of call to the program log.

(static) warn( …messageopt )

Logs a "WARNING" message to the program log and triggers Script.warningMessage. The message logged is "WARNING - " followed by the message values separated by spaces.

Parameters

Name Type Attributes Description
message * <optional>
<repeatable>

The message values to log.