1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
6 * Namespace: OpenLayers.Console
7 * The OpenLayers.Console namespace is used for debugging and error logging.
8 * If the Firebug Lite (../Firebug/firebug.js) is included before this script,
9 * calls to OpenLayers.Console methods will get redirected to window.console.
10 * This makes use of the Firebug extension where available and allows for
11 * cross-browser debugging Firebug style.
14 * Note that behavior will differ with the Firebug extention and Firebug Lite.
15 * Most notably, the Firebug Lite console does not currently allow for
16 * hyperlinks to code or for clicking on object to explore their properties.
19 OpenLayers.Console = {
21 * Create empty functions for all console methods. The real value of these
22 * properties will be set if Firebug Lite (../Firebug/firebug.js script) is
23 * included. We explicitly require the Firebug Lite script to trigger
24 * functionality of the OpenLayers.Console methods.
29 * Log an object in the console. The Firebug Lite console logs string
30 * representation of objects. Given multiple arguments, they will
31 * be cast to strings and logged with a space delimiter. If the first
32 * argument is a string with printf-like formatting, subsequent arguments
33 * will be used in string substitution. Any additional arguments (beyond
34 * the number substituted in a format string) will be appended in a space-
44 * Writes a message to the console, including a hyperlink to the line
45 * where it was called.
47 * May be called with multiple arguments as with OpenLayers.Console.log().
56 * Writes a message to the console with the visual "info" icon and color
57 * coding and a hyperlink to the line where it was called.
59 * May be called with multiple arguments as with OpenLayers.Console.log().
68 * Writes a message to the console with the visual "warning" icon and
69 * color coding and a hyperlink to the line where it was called.
71 * May be called with multiple arguments as with OpenLayers.Console.log().
80 * Writes a message to the console with the visual "error" icon and color
81 * coding and a hyperlink to the line where it was called.
83 * May be called with multiple arguments as with OpenLayers.Console.log().
91 * APIFunction: userError
92 * A single interface for showing error messages to the user. The default
93 * behavior is a Javascript alert, though this can be overridden by
94 * reassigning OpenLayers.Console.userError to a different function.
96 * Expects a single error message
101 userError: function(error) {
106 * APIFunction: assert
107 * Tests that an expression is true. If not, it will write a message to
108 * the console and throw an exception.
110 * May be called with multiple arguments as with OpenLayers.Console.log().
115 assert: function() {},
119 * Prints an interactive listing of all properties of the object. This
120 * looks identical to the view that you would see in the DOM tab.
128 * APIFunction: dirxml
129 * Prints the XML source tree of an HTML or XML element. This looks
130 * identical to the view that you would see in the HTML tab. You can click
131 * on any node to inspect it in the HTML tab.
136 dirxml: function() {},
140 * Prints an interactive stack trace of JavaScript execution at the point
141 * where it is called. The stack trace details the functions on the stack,
142 * as well as the values that were passed as arguments to each function.
143 * You can click each function to take you to its source in the Script tab,
144 * and click each argument value to inspect it in the DOM or HTML tabs.
147 trace: function() {},
151 * Writes a message to the console and opens a nested block to indent all
152 * future messages sent to the console. Call OpenLayers.Console.groupEnd()
153 * to close the block.
155 * May be called with multiple arguments as with OpenLayers.Console.log().
160 group: function() {},
163 * APIFunction: groupEnd
164 * Closes the most recently opened block created by a call to
165 * OpenLayers.Console.group
167 groupEnd: function() {},
171 * Creates a new timer under the given name. Call
172 * OpenLayers.Console.timeEnd(name)
173 * with the same name to stop the timer and print the time elapsed.
181 * APIFunction: timeEnd
182 * Stops a timer created by a call to OpenLayers.Console.time(name) and
183 * writes the time elapsed.
188 timeEnd: function() {},
191 * APIFunction: profile
192 * Turns on the JavaScript profiler. The optional argument title would
193 * contain the text to be printed in the header of the profile report.
195 * This function is not currently implemented in Firebug Lite.
198 * title - {String} Optional title for the profiler
200 profile: function() {},
203 * APIFunction: profileEnd
204 * Turns off the JavaScript profiler and prints its report.
206 * This function is not currently implemented in Firebug Lite.
208 profileEnd: function() {},
212 * Writes the number of times that the line of code where count was called
213 * was executed. The optional argument title will print a message in
214 * addition to the number of the count.
216 * This function is not currently implemented in Firebug Lite.
219 * title - {String} Optional title to be printed with count
221 count: function() {},
223 CLASS_NAME: "OpenLayers.Console"
227 * Execute an anonymous function to extend the OpenLayers.Console namespace
228 * if the firebug.js script is included. This closure is used so that the
229 * "scripts" and "i" variables don't pollute the global namespace.
233 * If Firebug Lite is included (before this script), re-route all
234 * OpenLayers.Console calls to the console object.
236 var scripts = document.getElementsByTagName("script");
237 for(var i=0, len=scripts.length; i<len; ++i) {
238 if(scripts[i].src.indexOf("firebug.js") != -1) {
240 OpenLayers.Util.extend(OpenLayers.Console, console);