JavaScript AJAX remote logger

流过昼夜 提交于 2019-12-20 20:02:47

问题


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

Thanks STeN


回答1:


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");



回答2:


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.



来源:https://stackoverflow.com/questions/8296079/javascript-ajax-remote-logger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!