If you are already using jQuery, I can heartily recommend the jQuery Debug plugin (a.k.a., jquery.debug.js). See http://trainofthoughts.org/blog/2007/03/16/jquery-plugin-debug/.
This plugin allows you to switch debug logging off or on via a global switch. Logging looks like this:
$.log('My value is: ' + val);
Output is sent to console.log under Firefox and is written to a div block inserted at the bottom of the page on other browsers.