dominoExperts.com - Powered by Domino 8.5.2 Domino Accelerator Pack
- Cache, Combine, JS-Minify and Compress content
Lotus Triple Search DominoExperts + Blogs + R8 forum
dominoExperts.com -> Script vault -> Ajax

 Creating a server side log of JavaScript errors


Tomas NielsenPost date: 2007-04-27 16:10

While surfing the web I stumbled upon this little snippet that catches some errors for you.

Code:
var errorHandler = function(msg, url, linenumber) {
alert("Error: " + msg + " for " + url + " at " + linenumber);
};
window.onerror = errorHandler;

Not so much new about that. You can use try catch too to get at the info.

But I was thinking more in the direction of:
What if you took that error message and sent it back to the server in an Ajax request?

You could get a nice JavaScriptErrorLog.nsf of what JavaScript errors your users would encounter and where in your site it would occur. You could add in the name of the user and what roles he has, cookies and browserversion also if needed.

Anyone who wants to join in and code the log application? I think I have a good outline of what would be needed.


Fredrik StöckelPost date: 2007-04-27 17:08

The latest version of openLog (1.5 BETA) over at openNTF.org contains a js-loghandler (XHR style).

 

 


Tomas NielsenPost date: 2007-04-27 20:11

But they are not using Ajax to log the event as I can see. They launch a link.

I would rather have a log of errors that have happened without sending the user to some error page.


Joacim BoivePost date: 2007-05-10 14:53

Sure you COULD use AJAX, but it's overkill for this application.

On the top of my head - Something like this could be sufficent:

var traceError=new Image();

traceError.src=<your_log_db>/<formname>?CreateDocument&Error=<Something>&Line=<errLine>

Note! Remeber to escape the characters properly.

 

In the document you have corresponding fields to store the different elements: @URLQueryString("Error") etc...

To get the originating page you can simply use the CGI variable: HTTP_referer.

 

You can use this approach to log anything you like even if the user don't have JS enabled by including an IMG-tag on your page, like so:

<img src=<your_log_db>/<formname>?CreateDocument&<whatEver>=<something> width="1" height="1" alt="logTracer" style="display: none;" />

 

I'm using it and it's blistering quick on a optimized database. It takes under 20ms to create a log document that contains only one elment, expect this to increase as you add fields/logic.

 

 

/Jocke

 


Tomas NielsenPost date: 2007-05-10 19:43

Cool, that is in the line of what I was thinking! (And welcome here Joacim!)

I have something similar at a customer solution but in the general error form. I log absolutely everything I can think of there. It is great to know what kind of browser, cookie and the users name, roles and so on when something goes wrong.


Joacim BoivePost date: 2007-05-11 09:55

Feels good to be here, this page got potential.

 

/J




RSS feed
Subscribe to Forum

Share this page

Top posters
Tomas Nielsen212
Joacim Boive27
Fredrik Stöckel27
Danne14
Niklas Waller13
Kenneth Haggman11
Bryan Kuhn10
Daniel Lehtihet9
Jonas Israelsson8
dm997