8

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> on 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...

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
STeN
  • 6,262
  • 22
  • 80
  • 125

2 Answers2

14

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

http://www.slideshare.net/nzakas/enterprise-javascript-error-handling-presentation

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");
mamoo
  • 8,156
  • 2
  • 28
  • 38
  • Wow! Looks pretty clever, do you have some server side implementation for it? Some php/tomcat servlet with UI script which displays it? It would be nice to have the server side as well... – STeN Nov 28 '11 at 13:31
  • No php code unfortunately, but it should be fairly simple: just grab the params and call the log handler. – mamoo Nov 28 '11 at 13:36
  • 1
    I believe it should be img.src **=** "log.php", not img.src **+** log.php. – Ben Fulton Jul 26 '12 at 19:27
  • IIS will log your querystrings for you. Quick and dirty hack. Clever. – Necoras May 02 '17 at 21:22
3

Warning: No Longer Working!

As @JohnSmith commented below, the solution suggested here appears to no longer be functional.


An alternative to hosting your own server logging might be JSConsole.com. It's a general purpose remote debugger for JavaScript. Just register a listener, paste the script tag it generates into your page, then fire up an instance on any device. The debugger is bidirectional, so not only does the logging get forwarded to the remote console on JSConsole, you have full access to the JS environment on the remote client.

merv
  • 67,214
  • 13
  • 180
  • 245
  • Before anybody else wastes an hour troubleshooting, like I just did, the JSConsole.com remote logging has been disabled, but the guy didn't bother to let anyone know. It says it works, but it doesn't. – John Smith Jul 28 '19 at 00:17
  • Thanks for commenting, @JohnSmith, and sorry about the trouble! I've updated the answer to make your finding prominent. – merv Jul 29 '19 at 03:14
  • Thanks, and thanks for being more polite in the tone of your reply than I was in my (frustrated) comment. – John Smith Aug 14 '19 at 18:55