STeN STeN - 1 year ago 81
Ajax Question

JavaScript AJAX remote logger

I am working on JavaScript application on the platform which does not have support for log output, does not allow opening new windows for logger output and has nothing like Firebug or Safari debugger on it...

So far I was using the

floating <div>
z-index 2
and I logged the text inside, but this is not sufficient. I am looking for some lightweight JavaScript JSONP logger and some PHP or Tomcat server counterpart...


Answer Source

I recently stumbled upon this presentation of N. Zakas, and implemented the technique explained there. It is quite simple but IMHO very effective

the idea is to simply issue a call to a server side component (I used a .net handler but it could be a php file as well) which takes some param, log the param values and returns a 1x1 image stream back. What I like the most is that there's no need to involve ajax calls at all.

The code from the presentation is as follows:

    function log(severity, message) {
      var img = new Image();
      img.src = "log.php?sev=" + encodeURIComponent(severity) +
      "&msg=" + encodeURIComponent(message);

    log(1, "something bad happened");