Skip to content

Instantly share code, notes, and snippets.

@lucamilan
Created May 15, 2012 10:22
Show Gist options
  • Save lucamilan/2700630 to your computer and use it in GitHub Desktop.
Save lucamilan/2700630 to your computer and use it in GitHub Desktop.
Javascript Logging (Server & Client)
// client side logging
window.console = window.console || function () { var a = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; window.console = {}; for (var b = 0; b < a.length; ++b) window.console[a[b]] = function () { } } ();
// server side logging
window.onerror = function (msg, url, line) {
if (encodeURIComponent && window.XMLHttpRequest && window.navigator) {
try {
var req = new XMLHttpRequest();
var params = "agent=" + navigator.userAgent + "&line=" + line + "&msg=" + msg + "&url=" + encodeURIComponent(url);
req.open("POST", "/LogJs.aspx", true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.send(params);
} catch (e) { }
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment