Logging in Javascript

Wednesday 15th October, 2008

Today’s Ajaxian article about the Blackbird Javascript logging library has prompted a stream of comments asking what advantage this gives over console.log() in Firebug.

I think both the commenters and the Blackbird author have missed a very important aspect of logging in Javascript, namely the ability to record errors outside your own session, i.e. server-side.

This is all that’s missing (in roughly JQuery syntax for brevity):

window.onerror = function(e)
    // get the error data
    if (!e) e = window.error;
    // save error and UI activity for context
    $.post( log_url, 
            // do callback if necessary