MacPython Logo from __future__ import *

buy music albums Silver Apples buy mp3 albums Tarrus Riley buy tracks mp3 Kravits buy Reaper albums mp3 buy Kravits albums music buy music Evita CD online albums mp3 Silver Apples download Madonna CD music buy tracks music Kravits download music albums Silver Apples

2005-07-03

Bookmarklet Based Debugging

Filed under: AJAX, MochiKit, debugging, javascript — bob @ 3:04 pm

I haven't seen this discussed much, but one of the techniques I've found really useful for debugging JavaScript is what we've been calling BBD: Bookmarklet Based Debugging. The reason we've settled on this is that it's entirely unobtrusive. Our pages look exactly how they're supposed to look, with no extra "debugging" widgets or text sitting around on the page. However, if I need more information, I just whack a bookmarklet and I get all of the information I need. I'm aware that there are various bookmarklets out there that display various kinds of JavaScript information that might be useful for debugging, but not in such a way that you instrument your page for application specific BBD. Also, most of the JavaScript debugging bookmarklets out there only work in Mozilla, and I do most of my development in Safari.

http://undefined.org/mochikit/img/mochikit_bbd_1.png

The reason this works for us is because we use a common logging infrastructure across our whole web app: MochiKit.Logging. This, and the rest of MochiKit, will be liberally licensed open source (likely MIT) in less than two weeks. MochiKit.Logging is vaguely similar to Python's logging module or Apache's log4j, but without all of the headaches and mindless configuration sludge.

Typical usage for our Logger object looks like this:

// these are global functions for convenience:
log("some", "objects", "here", "at", "the", "INFO", "level");
logDebug("some", "objects", "here", "at", "the", "DEBUG", "level");
// or more generally:
logger.baseLog(logLevel, objects...);

When one of these log methods are called, two things happen:

  1. Any attached listeners to the logger are notified (which may or may not do something interesting with the log message)
  2. The global logger stuffs the log message away in a log buffer (of configurable size, by default it's infinite) for easy retrieval

Listeners are really just for future enhancements (i.e. "real-time" log window by bookmarklet), but our current bookmarklet simply formats the last 40 messages or so as an alert message and spits it to the browser.

Currently, the bookmarklet URL for MochiKit.Logging's brain dump is simply: javascript:logger.debuggingBookmarklet(), which allows for future improvements (i.e. something better than alert(...)) without "upgrading" the bookmarkets in everyone's browser.

UPDATE:
MochiKit is now available. Check it out at mochikit.com!

3 Comments »

  1. Sounds great! You talking about MochiKit makes me wish I had a reason to do JavaScript hacking :D

    Are you going to peddle MochiKit as an alternative for Prototype and the other JavaScript libraries often used by Ruby on Rails apps, or is this intended for other uses less suitable to Ruby on Rails? I ask this because Ruby on Rails seems like a great example of an existing, very nice, very well-done web app environment that’s growing in popularity and is adding more and more JavaScript coolness (like built-in AJAX support and such), and I know Prototype is pretty popular in the RoR crowd.

    Also, where’d the name MochiKit come from?

    Comment by Kevin Ballard — 2005-07-03 @ 6:00 pm

  2. I don’t care about Ruby on Rails. If it turns out that MochiKit is useful for RoR development, great, if not, oh well. It’s certainly not a drop-in replacement for Prototype, so if RoR depends on that Prototype’s API, then it’s not going to be useful.

    However, it *is* an alternative to Prototype for people using JavaScript. I specifically wrote it because Prototype nor anything else I could find was good enough for us.

    The name is derivative of our company’s.. it’ll be more obvious soon!

    Comment by Bob Ippolito — 2005-07-03 @ 6:15 pm

  3. I think it’s sad that users of THE scripting language for the web have to show quite a degree of creativity only to be able to debug their programms properly. Really kind sad. But then I’ve noted years ago that Javascript is as broken as a system comes. Oh, as we mention it. Hello Web 1.0, in brokeness we’re bound.

    Comment by Florian — 2005-07-04 @ 2:28 pm

RSS feed for comments on this post.

Leave a comment

Powered by WP-Hashcash.

Powered by WordPress