OpenLayers OpenLayers

Ticket #507 (closed feature: fixed)

Opened 3 years ago

Last modified 3 years ago

debug mode

Reported by: tschaub Assigned to: tschaub
Priority: minor Milestone: 2.5 Release
Component: tests Version:
Keywords: Cc:
State:

Description

It seems that there is consensus about having the option to run OpenLayers in debug mode (http://www.nabble.com/OpenLayers-%27Debug-Mode%27-tf3248860.html).

Though I understand the resistance to add in a logging framework, I wanted to make the case for Firebug (and Firebug Lite).

Everybody knows that alerts make for awkward debugging (nobody wants a modal dialog in a big loop). Firebug's console calls improve on alert calls by giving modeless messages, but that's only a slight improvement. Real debugging comes in when you can interact with the state of the application.

If OpenLayers adds its own version of console logs (or warns or errors), then this will provide the first clue to users who run into trouble. I'm assuming many people won't be able to do much with the output (the log, warning, or error message). By giving users the option of building OpenLayers with Firebug Lite (for non Firefox browsers), we could allow for cross browser interactive debugging.

I've added a debug sandbox with Firebug Lite built in. Using the patch from #248, I've added a console.warn() call when the redundant layer is added. (Try http://dev.openlayers.org/sandbox/tschaub/debug/examples/debug.html in a non-Firefox browser to see it in action.) This doesn't give any new functionality to Firefox users with Firebug - for others, it adds Firebug like functionality.

A user with a problem could build OpenLayers with a debug profile or point their script tag to someplace where one was already built (not "built" but http://dev.openlayers.org/sandbox/tschaub/debug/lib/OpenLayers.js would work). Then adding OpenLayers.debug(true) before constructing the map gives them Firebug (in IE, Safari, Opera, and Firefox without Firebug).

In addition to getting the nice warning about adding a redundant layer, they can also toy around with things like map.layers.length (assuming map is a global variable).

For development alone, I think there is good reason to use Firebug Lite (cross-browser debugging).

This does mean that the code will get littered with console.warn() and console.error() calls. The OpenLayers.ignoreConsole() call in the map constructor makes these harmless in browsers without Firebug. If the addition of the bare console object is objectionable, it could all be tucked in the OpenLayers namespace.

If there is going to be a debug mode, it means that warnings and errors will be scattered throughout the code. With the Firebug (Lite) method, at least these aren't all wrapped in if(OpenLayers.DEBUG) {} or other. And, it wouldn't be that big a feat to modify jsmin.py so that console\..*?; calls were stripped if that is a concern.

And, building with Firebug does nothing if you already have Firefox with Firebug - it just lets us make use of a very functional wheel.

Attachments

debug.patch (4.9 kB) - added by tschaub on 02/22/07 06:22:11.
modifications beyond firebug.js
debug.better.patch (103.7 kB) - added by tschaub on 04/01/07 16:28:16.
unobtrusive debugging framework for all browsers
debug.2.patch (99.1 kB) - added by crschmidt on 04/01/07 17:30:56.
debug.3.patch (55.4 kB) - added by tschaub on 06/05/07 03:05:48.
Adds OpenLayers.Console - and Firebug like debugging cross-browser
debug.4.patch (31.6 kB) - added by tschaub on 06/05/07 05:51:56.
easier upgrades to Firebug Lite
debug.5.patch (34.0 kB) - added by tschaub on 06/05/07 06:33:22.
a complete patch
debug.6.patch (33.2 kB) - added by tschaub on 06/07/07 20:32:09.
includes license.txt for Firebug Lite

Change History

02/22/07 06:22:11 changed by tschaub

  • attachment debug.patch added.

modifications beyond firebug.js

02/22/07 20:06:39 changed by tschaub

Ok, and if a debug build is too onerous, you can add a simple tag

<script src="../lib/Firebug/debug.js"></script>

to trigger debugging. Can't get much simpler than that in my opinion.

03/09/07 22:13:06 changed by sderle

  • owner set to tschaub.
  • component changed from general to tests.
  • milestone set to 2.5 Release.

04/01/07 16:27:12 changed by tschaub

Ok, ignore most of the above. I'm attaching a new patch that I consider a very unobtrusive debugging option. It works like this:

1) developers put calls to OpenLayers.console.warn(), OpenLayers.console.error(), or any number of other console methods in the code where appropriate

2) users who are having trouble with their applications add the following tag after the OpenLayers.js tag

<script src="../lib/Firebug/DebugOpenLayers.js"></script>

3) with the debugging script included, hitting F12, Ctrl+Shift+L (or ?+Shift+L on a Mac) opens a debugging console - Firebug on browsers with the Firebug extension and Firebug Lite on all other browsers

4) that's it - without the debugging script tag, the OpenLayers.console.* calls are harmless

This adds nothing (significant) to the OpenLayers build. Also, if there is a reason not to distribute Firebug Lite with the library, the debugging script tag can point to a script hosted anywhere (on OpenLayers.org for example).

Example: examples/debug.html

Tests in tests/BaseTypes/test_Console.html. The only real diff in lib/OpenLayers/BaseTypes.js. What does the trick? lib/Firebug/DebugOpenLayers.js.

04/01/07 16:28:16 changed by tschaub

  • attachment debug.better.patch added.

unobtrusive debugging framework for all browsers

04/01/07 17:30:56 changed by crschmidt

  • attachment debug.2.patch added.

06/05/07 03:04:36 changed by tschaub

  • keywords set to review.

Ok, I've been enjoying using this for a while - will happily commit if it passes review (debug.3.patch).

As described above, if a user puts the DebugOpenLayers.js script tag after the OpenLayers.js script tag - they get a Firebug like console (cross-browser). If the tag is not included, OpenLayers.Console calls are harmless.

The only change reflected here is capitalization of the OpenLayers.Console namespace.

Next discussion will have to be about try/catch, when to throw, what to throw, and which OpenLayers.Console methods to use where.

Please review.

06/05/07 03:05:48 changed by tschaub

  • attachment debug.3.patch added.

Adds OpenLayers.Console - and Firebug like debugging cross-browser

06/05/07 03:34:38 changed by tschaub

  • keywords deleted.

cancel that, better idea

06/05/07 05:50:36 changed by tschaub

Ok, simple patch - much nicer. This uses Firebug Lite as is (with one small patch related to a legitimate Firebug issue). The OpenLayers/Console.js script should be included in any build that contains calls to OpenLayers.Console methods.

To run an application in debug mode, the script tag pointing to Firebug/firebug.js is placed before the OpenLayers.js tag.

Please review.

06/05/07 05:51:56 changed by tschaub

  • attachment debug.4.patch added.

easier upgrades to Firebug Lite

06/05/07 05:52:23 changed by tschaub

  • keywords set to review.

06/05/07 06:33:22 changed by tschaub

  • attachment debug.5.patch added.

a complete patch

06/07/07 20:32:09 changed by tschaub

  • attachment debug.6.patch added.

includes license.txt for Firebug Lite

06/11/07 23:14:41 changed by crschmidt

  • keywords changed from review to commit.

It's good. Commit it.

06/11/07 23:18:38 changed by tschaub

  • keywords deleted.
  • status changed from new to closed.
  • resolution set to fixed.

resolved with r3320