Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log client side errors to the server [duplicate]

Possible Duplicate:
Logging Clientside JavaScript Errors on Server

How can I log client side javascript errors to the server? I'm using jQuery and MVC.

like image 819
Karl Glennon Avatar asked May 13 '10 09:05

Karl Glennon


People also ask

What is server side logging?

Server-side logging is available on a URL group or server session. When logging is enabled on a server session, it functions as centralized form of logging for all the URL groups under the server session. When logging is enabled on a URL group, logging is performed only on requests that are routed to the URL Group.

What are logging errors?

An error log is a file that contains detailed records of error conditions a computer software encounters when it's running. The name is generic: sometimes, an application can log non-error type messages in its error log. However, error logs are generally meant to record only error messages generated by a program.

What are server side errors?

Server side errors occur when a failure to render a page falls on the server. A large spike in 500 or 503 errors could indicate the inability for the site's web hosting and server to manage the requirements of the site, resulting in downtime for visitors.


2 Answers

Since they're client-side errors, you'll have to send them to the server using XMLHttpRequest. You could use try...catch statements or window.onerror:

window.onerror = function (msg, url, line)
{
    var message = "Error in "+url+" on line "+line+": "+msg;
    $.post("logerror.aspx", { "msg" : message }); 
}

Be aware that line and url can be very inaccurate in IE versions prior to 8.

like image 178
Andy E Avatar answered Sep 19 '22 06:09

Andy E


You could use my log4javascript, which has an appender that uses XMLHttpRequest to log to the server:

var log = log4javascript.getLogger("serverLog");
var ajaxAppender = new log4javascript.AjaxAppender("clientlogger.jsp");
log.addAppender(ajaxAppender);

try {
    nonExistentFunction();
} catch(ex) {
    log.error("Something's gone wrong!", ex);
}
like image 30
Tim Down Avatar answered Sep 21 '22 06:09

Tim Down