Skip to main content

High Fidelity API Reference

Tools Used: JavaScript, JSDoc, GitHub Pages, Markdown, HTML, CSS


console

MethodsMethod Details

The console API provides program logging facilities.

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


Methods

NameReturn ValueSummary
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

assert

(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

NameTypeAttributesDescription
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("hifi-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.

clear

(static) clear( )

Clears the Developer > Scripting > Script Log debug window.

debug

(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

NameTypeAttributesDescription
message

*

<optional>
<repeatable>

The message values to log.

error

(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

NameTypeAttributesDescription
message

*

<optional>
<repeatable>

The message values to log.

exception

(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

NameTypeAttributesDescription
message

*

<optional>
<repeatable>

The message values to log.

group

(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

NameTypeDescription
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

groupCollapsed

(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

NameTypeDescription
message

*

The message value to log.

groupEnd

(static) groupEnd( )

Finishes a group of indented console.log messages.

info

(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

NameTypeAttributesDescription
message

*

<optional>
<repeatable>

The message values to log.

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

NameTypeAttributesDescription
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]

time

(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

NameTypeDescription
name

string

The name of the timer.

Example: Time some processing
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i &lt; 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

timeEnd

(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

NameTypeDescription
name

string

The name of the timer.

trace

(static) trace( )

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

warn

(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

NameTypeAttributesDescription
message

*

<optional>
<repeatable>

The message values to log.