Wednesday, December 28th, 2005

Logging and Ajax: Beyond alert()’s

Category: Articles, JavaScript, Testing, Toolkit

Eric Spiegelberg has written Log4Ajax , an article with corresponding demo code for logging ajax applications. Eric’s article builds upon an earlier, simpler system for logging from Joshua Gitlin’s article Errors and Ajax.

It details a logging system in javascript displayed to an in browser console, with the option of sending messages to the server (via ajax) in order to persist them. Eric uses the java based log package log4j on the server side to capture the log messages from the client, but the idea could easily be adapted to whatever sort of server side logging system you want.

He also talks about some possible improvements, like filter levels for client and server and a queue to keep your server from getting hammered by debug messages. An opportunity for some open source development, perhaps (although I didn’t see mention of the license terms anywhere).

You can download the code used at the sourceforge project page, and also view a live demo. A simple yet powerful option for your logging when alert() messages won’t cut it.

Update: Andre wrote to let us know about his recent release of JSLog, another javascript logging tool. JSLog logs to an expandable window in your browser and can be turned on or off via a single config setting. There is one script file and its 6k with no dependancies.

JSLog does not have the server side component, and Andre explains why he left it out:

[I] decided to stick with a transient browser display for two reasons: 1) it met all of my debugging needs in that form; 2) introduction of a server-side component complicates the deployment significantly, and reduces the portability of the tool.

So if you don’t need the server side piece or just want to compare the options, check out JSLog, or see the optional Scriptaculous effects at the live demo.

log4ajax example

Posted by Rob Sanheim at 9:53 am
1 Comment

3.3 rating from 10 votes

1 Comment »

Comments feed

This looks like a nice, small solution. It’s also worth noting that the overall excellent MochiKit library also includes a logging package (and the wiki has code you can include in your page if you want logging to appear in a div there…)

Comment by Kevin Dangoor — December 29, 2005

Leave a comment

You must be logged in to post a comment.