edX Log Catching - dan7davis/Lambda GitHub Wiki
One problem of the current edX logging mechanism is that we only receive a log dump every 24 hours. Some of our interventions require close to real-time logging, so for now we resort to duplicating the edX logs to our own server. One simple way of this duplication process is the following code snippet:
// This will break studio if it runs inside of it,
// so this IF statement make it so the XHR intercept only fires if not in studio
if ( url.includes('studio') === false) {
(function() {
var origSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(data) {
console.log("[AJAX SEND CAUGHT]");
//do something with this data
origSend.call(this,data); //lets not forget to send the data to its originally intended location
};
})();
} else {
console.log("You're in studio.")
};
which intercepts XHR requests (edX way of transmitting logs). Whatever needs to be done with the data can now be done.