Yet another JavaScript logger

While writing Beginning Google Maps Applications, I grew accustomed to using GLog.write() while debugging any JavaScript I was working on. It was a wonderful alternative to alert(). That was great while I was working on map related projects but without the Google Maps API, it wasn’t there. Finally the other day, frustrated the 100th time I accidentally put my browser into an infinite alert loop, I decided to write up a quick logger myself. Afterwards, I realized there were already a bunch on the net but I had fun writing my own and even learned a few DOM tricks. For any of you out there who want to use it, go nutz. I’ve called it JSLog and the primary methods are JSLog.write(); which outputs escaped angle brackets while JSLog.writeHTML() outputs the raw input.

JSLog Window

The best part is now when debugging things like Prototype AJAX calls, you can easily log and see all the exceptions!

new Ajax.Request( 'example.php', {
    onComplete:function(request){
        try {
            //do whatever you need to an errors will be logged!
        } catch (e) {
            if(JSLog) JSLog.write(e);
        }
    }
});

No more errors floating into dream land!

To use it, just download the source or add

<script type="text/javascript" src=http://jeffreysambells.com/openprojects/JavaScript/JSLog.js"></script>

to the head of your document.

2 Comments »

  1. Hello,
    I’m here to drop a quick note to say thank you for posting a GPS Google map
    of a North Tea Lake trip in Algonquin Park.
    (http://jeffreysambells.com/openprojects/GMaps/algonquin/northTeaLake.kml)

    I found it through a google search while using Google-Earth to try and pinpoint the exact location of my first family canoe trip. My father led us through the North Tea, Manitou, Biggar- circuit in ‘89.
    Thanks to your map, mission accomplished!
    All the best,
    Randomly,
    Matt, Ontario.

  2. [...] A Javascript Logger. This is essential for my debugging needs. When I first started working with Google maps and I was introduced to Google’s GLog I thought I’d died and gone to hevan. Theres nothing more annoying than having to click “ok” on a 100 alert boxes because while trying to debug your code you accidentally added an alert() to a loop. Jeff wrote a great one recently that I use in all of my scripts. The ability he added to turn off the logging by simply setting a variable so I don’t have to go through my code and delete all references to the logger is really great! You can learn more about it here. [...]

RSS feed for comments on this post. | TrackBack URI

Leave a comment

Content & imagery © Copyright 2007 by Jeffrey Sambells as appropriate.