[OpenLayers-Dev] Debugging OpenLayers
Tim Schaub
noreply at geocartic.com
Tue Jun 5 03:15:48 EDT 2007
If we (OpenLayers developers)
1) threw exceptions where appropriate,
2) wrapped calls in try/catch to handle exceptions, and
3) had a framework to log error messages,
then OpenLayers applications would be easier to debug.
Starting from the bottom, we can get a logging framework for cheap by
using Firebug Lite. Firebug Lite extends a limited set of Firebug
debugging capability to all browsers (that matter).
The latest patch to ticket #507 allows Firebug Lite to sit next to
OpenLayers in a comfortable way [1]. Users (application developers)
would trigger "debug" mode by including a script tag pointing to
firebug.js before their OpenLayers.js tag.
In debug mode, calls to OpenLayers.Console.log, OpenLayers.Console.warn,
OpenLayers.Console.error, and a handful of other OpenLayers.Console
methods show up in a Firebug looking console (or Firebug where available).
Outside of debug mode, calls to OpenLayers.Console methods do nothing
(call function() {}).
If this sounds like a good idea to folks, I'd encourage us to start
using OpenLayers.Console methods and come up with some best practices
for the first two points above.
If you care nothing about exception handling, this patch does very
little that should concern you - it adds 15 lines of code to the full
build. If there is a concern about the single-file size as
OpenLayers.Console calls are added to the library, jsmin could be
tweaked to strip these in the build process. Left in, they do no harm.
I've posted an example page running in debug mode [2]. In non-Firefox
browsers, you launch the console with F12 or Ctrl+Shift+L (?+Shift+L on
Mac) - as with the regular Firebug console.
Let me know what you think.
Tim
[1] http://trac.openlayers.org/attachment/ticket/507/debug.5.patch
(note that the patch refers to images that come with Firebug Lite)
[2] http://dev.openlayers.org/sandbox/tschaub/debug/examples/debug.html
More information about the Dev
mailing list