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.
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.
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.
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.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With