org.xwiki.gwt.user.client
Class Console

java.lang.Object
  extended by org.xwiki.gwt.user.client.Console

public class Console
extends Object

Interface to the browser's console. Useful for logging and profiling. This class provides an empty implementation. Each browser has its own console API. You should extend this class and overwrite the needed methods by using that API.

Version:
$Id: 7ce39a98bb0ebd8bb4765fe67d9be4ed15d7e6fb $

Constructor Summary
Console()
           
 
Method Summary
 void addBreakPoint()
          Adds a break point for the debugger.
 void assertTrue(boolean expression, Object... objects)
          Tests that an expression is true.
 void count(String title)
          Writes the number of times that the line of code where count was called was executed.
 void debug(Object object, Object... objects)
          Writes a message to the console, including a hyperlink to the line where it was called.
 void dir(Object object)
          Prints an interactive listing of all properties of the given object.
 void dirxml(com.google.gwt.dom.client.Node node)
          Prints the XML source tree of an HTML or XML element.
 void error(Object object, Object... objects)
          Writes a message to the console with the visual "error" icon and color coding and a hyperlink to the line where it was called.
static Console getInstance()
           
 void group(Object object, Object... objects)
          Writes a message to the console and opens a nested block to indent all future messages sent to the console.
 void groupEnd()
          Closes the most recently opened block created by a call to group(Object, Object...).
 void info(Object object, Object... objects)
          Writes a message to the console with the visual "info" icon and color coding and a hyperlink to the line where it was called.
 void log(Object object, Object... objects)
          Writes a message to the console.
 void profile(String title)
          Turns on the JavaScript profiler.
 void profileEnd()
          Turns off the JavaScript profiler and prints its report.
 void time(String name)
          Creates a new timer under the given name.
 void timeEnd(String name)
          Stops a timer created by a call to time(String) and writes the time elapsed.
 void trace()
          Prints an interactive stack trace of JavaScript execution at the point where it is called.
The stack trace details the functions on the stack, as well as the values that were passed as arguments to each function.
 void warn(Object object, Object... objects)
          Writes a message to the console with the visual "warning" icon and color coding and a hyperlink to the line where it was called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Console

public Console()
Method Detail

getInstance

public static Console getInstance()
Returns:
The console instance in use.

time

public void time(String name)
Creates a new timer under the given name. Call timeEnd(String) with the same name to stop the timer and print the time elapsed.

Parameters:
name - The name of the timer.

timeEnd

public void timeEnd(String name)
Stops a timer created by a call to time(String) and writes the time elapsed.

Parameters:
name - The name of the timer.

profile

public void profile(String title)
Turns on the JavaScript profiler.

Parameters:
title - The text to be printed in the header of the profile report.

profileEnd

public void profileEnd()
Turns off the JavaScript profiler and prints its report.


count

public void count(String title)
Writes the number of times that the line of code where count was called was executed.

Parameters:
title - The message printed in addition to the number of the count.

log

public void log(Object object,
                Object... objects)
Writes a message to the console. You may pass as many arguments as you'd like, and they will be joined together in a space-delimited line.
The first argument to log may be a string containing printf-like string substitution patterns. For example:
console.log("The %s jumped over %d tall buildings", animal, count);
The example above can be re-written without string substitution to achieve the same result:
console.log("The", animal, "jumped over", count, "tall buildings");
These two techniques can be combined. If you use string substitution but provide more arguments than there are substitution patterns, the remaining arguments will be appended in a space-delimited line, like so:
console.log("I am %s and I have:", myName, thing1, thing2, thing3);
If objects are logged, they will be written not as static text, but as interactive hyperlinks that can be clicked to inspect the object in Firebug's HTML, CSS, Script, or DOM tabs. You may also use the %o pattern to substitute a hyperlink in a string.
Here is the complete set of patterns that you may use for string substitution:
String Substitution Patterns
%s String
%d, %i Integer (numeric formatting is not yet supported)
%f Floating point number (numeric formatting is not yet supported)
%o Object hyperlink

Parameters:
object - First parameter is required. It can be either a formatting string or any ordinary object.
objects - Optional parameters.

debug

public void debug(Object object,
                  Object... objects)
Writes a message to the console, including a hyperlink to the line where it was called.

Parameters:
object - First parameter is required. It can be either a formatting string or any ordinary object.
objects - Optional parameters.
See Also:
log(Object, Object...)

info

public void info(Object object,
                 Object... objects)
Writes a message to the console with the visual "info" icon and color coding and a hyperlink to the line where it was called.

Parameters:
object - First parameter is required. It can be either a formatting string or any ordinary object.
objects - Optional parameters.
See Also:
log(Object, Object...)

warn

public void warn(Object object,
                 Object... objects)
Writes a message to the console with the visual "warning" icon and color coding and a hyperlink to the line where it was called.

Parameters:
object - First parameter is required. It can be either a formatting string or any ordinary object.
objects - Optional parameters.
See Also:
log(Object, Object...)

error

public void error(Object object,
                  Object... objects)
Writes a message to the console with the visual "error" icon and color coding and a hyperlink to the line where it was called.

Parameters:
object - First parameter is required. It can be either a formatting string or any ordinary object.
objects - Optional parameters.
See Also:
log(Object, Object...)

assertTrue

public void assertTrue(boolean expression,
                       Object... objects)
Tests that an expression is true. If not, it will write a message to the console and throw an exception.

Parameters:
expression - The expression to be evaluated.
objects - Optional parameters.
See Also:
log(Object, Object...)

dir

public void dir(Object object)
Prints an interactive listing of all properties of the given object.

Parameters:
object - The object whose properties will be displayed.

dirxml

public void dirxml(com.google.gwt.dom.client.Node node)
Prints the XML source tree of an HTML or XML element. You can click on any node to inspect it.

Parameters:
node - Any DOM node.

trace

public void trace()
Prints an interactive stack trace of JavaScript execution at the point where it is called.
The stack trace details the functions on the stack, as well as the values that were passed as arguments to each function. You can click each function to take you to its source, and click each argument value to inspect it.


group

public void group(Object object,
                  Object... objects)
Writes a message to the console and opens a nested block to indent all future messages sent to the console. Call groupEnd() to close the block.

Parameters:
object - First parameter is required. It can be either a formatting string or any ordinary object.
objects - Optional parameters.
See Also:
log(Object, Object...)

groupEnd

public void groupEnd()
Closes the most recently opened block created by a call to group(Object, Object...).


addBreakPoint

public void addBreakPoint()
Adds a break point for the debugger. If a debugger is present then the execution should stop at this point and continue from here in debug mode.



Copyright © 2004-2013 XWiki. All Rights Reserved.