Console API

the Console module provides function to access the console. Original documentation: Cordova Console.

Remark: Usage of cordova API needs http://tizen.org/privilege/filesystem.read privilege.

Since: 3.0

Table of Contents


Summary of Interfaces and Methods

Interface Method
ConsoleManagerObject
ConsoleManager
void log (DOMString text)
void error (DOMString text)
void warn (DOMString text)
void info (DOMString text)
void debug (DOMString text)
void assert (boolean expression, DOMString message)
void dir (Object obj)
void dirxml (Object obj)
void time (DOMString label)
void timeEnd (DOMString label)

1. Interfaces

1.1. ConsoleManagerObject

  [NoInterfaceObject] interface ConsoleManagerObject {
    readonly attribute ConsoleManager console;
  };
  Window implements ConsoleManagerObject;

Since: 3.0

The ConsoleManagerObject interface.

1.2. ConsoleManager

the ConsoleManager interface embodies Console module methods.
  [NoInterfaceObject] interface ConsoleManager {
    void log(DOMString text);
    void error(DOMString text);
    void warn(DOMString text);
    void info(DOMString text);
    void debug(DOMString text);
    void assert(boolean expression, DOMString message);
    void dir(Object obj);
    void dirxml(Object obj);
    void time(DOMString label);
    void timeEnd(DOMString label);
  };

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Methods

log
Prints a line of text to a standard output. The text will be logged as a standard message.
void log(DOMString text);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • text: The text to be printed.

Code example:

console.log("A is for Alice");

Output example:

A is for Alice
error
Prints a line of text to a standard output. The text will be logged as an error message.
void error(DOMString text);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • text: The text to be printed.

Code example:

console.error("B is for Bob");

Output example:

B is for Bob
warn
Prints a line of text to a standard output. The text will be logged as a warning message.
void warn(DOMString text);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • text: The text to be printed.

Code example:

console.warn("C is for Christopher");

Output example:

C is for Christopher
info
Prints a line of text to a standard output. The text will be logged as an info message.
void info(DOMString text);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • text: The text to be printed.

Code example:

console.info("D is for Dorothy");

Output example:

D is for Dorothy
debug
Prints a line of text to a standard output. The text will be logged as a debug message.
void debug(DOMString text);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • text: The text to be printed.

Code example:

console.debug("E is for Eve");

Output example:

E is for Eve
assert
If the specified expression is false, the message is written to the console.
void assert(boolean expression, DOMString message);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • expression: The expression to be evaluated.
  • message: The message to be displayed if an expression is false.

Code example:

var felix = "Felix";

/* This assertion checks whether the first letter in name "Felix" is "A". */
console.assert(felix.charAt(0) === "A", felix + " does not start with A");

Output example:

Felix does not start with A
dir
Prints a JavaScript representation of the specified object. If the object being logged is an HTML element, the JavaScript Object view is forced.
void dir(Object obj);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • obj: An object whose JavaScript representation will be printed.

Code example:

var john = {name: "John", surname: "Doe"};
console.dir(john.name);

Output example:

John
dirxml
Prints an XML/HTML Element representation of the specified object if possible or the JavaScript Object if it is not.
void dirxml(Object obj);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • obj: An object whose XML/HTML Element representation will be printed.

Code example:

var john = {name: "John", surname: "Doe"};
console.dirxml(john.surname);

Output example:

Doe
time
Starts a new timer with an associated label. When console.timeEnd() is called with the same label, the timer is stopped and the elapsed time is displayed in the console. Timer values are accurate to the sub-millisecond.
void time(DOMString label);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • label: The label to start timing with.

Code example:

console.time("Big array initialization");
var array = new Array(1000000);
for (var i = array.length - 1; i >= 0; i -= 1)
{
  array[i] = new Object();
}
console.timeEnd("Big array initialization");

Output example:

Big array initialization: 461.989ms
timeEnd
Stops the timer with the specified label and prints the elapsed time.
void timeEnd(DOMString label);

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/filesystem.read

Parameters:

  • label: The label associated to the timing (with the use of console.time() method).

Code example:

console.time("Big array initialization");
var array = new Array(1000000);
for (var i = array.length - 1; i >= 0; i -= 1)
{
  array[i] = new Object();
}
console.timeEnd("Big array initialization");

Output example:

Big array initialization: 461.989ms

2. Full WebIDL

module Console {
  Window implements ConsoleManagerObject;
  [NoInterfaceObject] interface ConsoleManagerObject {
    readonly attribute ConsoleManager console;
  };
  [NoInterfaceObject] interface ConsoleManager {
    void log(DOMString text);
    void error(DOMString text);
    void warn(DOMString text);
    void info(DOMString text);
    void debug(DOMString text);
    void assert(boolean expression, DOMString message);
    void dir(Object obj);
    void dirxml(Object obj);
    void time(DOMString label);
    void timeEnd(DOMString label);
  };
};