views:

88

answers:

3

I've got a serious javascript problem that is hard to reproduce in any of our DEV/TEST/PRD environments. Nonetheless, it is being reported consistently by our customers. Sometimes we think it's browser specific -- sometimes we think it's action specific -- sometimes we think it's cookie related. It's a tough one and we're getting pulled in too many different directions and they are all coming up short.

We believe the problem occurs in one of our main javascript files -- but that file is enormous. We've pin-pointed other problems in the past in this file -- and guarded against future problems using try/catch blocks successfully -- but, at this time we're very unsure where these newer problems are occurring.

We've searched through our server logs and the information we are finding there is not useful.

I am wondering if utilizing a javascript logging framework would help our problems. Will implementing something like "log4javascript" capture/log the activity of our users, not just us? Any advice? Anyone else been in this situation? What strategies did you employ to better understand your errors?

Thanks

+1  A: 

log4javascript's AjaxAppender can be used to send log messages to the server.

var log = log4javascript.getLogger("serverlog");
var ajaxAppender = new log4javascript.AjaxAppender("http://example.com/clientlogger");
log.addAppender(ajaxAppender);

You could put informational logging calls in your code and add a window.onerror handler to catch errors not caught by try/catch blocks in your code:

window.onerror = function(errorMsg, url, lineNumber) {
    log.fatal("Uncaught error " + errorMsg + " in " + url + ", line " + lineNumber);
};

You will also need to create something on the server to process the logging requests from the browser.

Tim Down
thank you Tim -- I'm investigating now!
rsturim
A: 

Can't say that I ever needed to log javascript, but if you just want to debug the code then I recommend:

Firebug is excellent for debugging, but it's an add-on for FireFox only....

If you can trigger the bug on IE, then also I recommend that you turn on the script debugger on that browser. With the script debugger on, you'll be at the very least able to pinpoint with exact accuracy the offending line generating the error. To turn it on, go to Tools->Advanced->Disable Script Debugging.

A: 

These guy (https://damnit.jupiterit.com/) also provide a free service (requires registration). It's quick and easy to set up depending on your needs it could be enough.

jfrobishow
Thank you jfrobishow. Looks interesting, we will also look into this!
rsturim