session-desktop/js/debugLog.js
lilia ae3a834b4c Log global errors
Use the global error handler, window.onerror, to catch miscellaneous
exceptions and pipe them into the debug log.

Fixes #456

// FREEBIE
2015-12-07 13:54:51 -08:00

41 lines
1.3 KiB
JavaScript

/*
* vim: ts=4:sw=4:expandtab
*/
(function () {
'use strict';
var MAX_MESSAGES = 1000;
var PHONE_REGEX = /\+\d{7,12}(\d{3})/g;
var debugLog = [];
if (window.console) {
console._log = console.log;
console.log = function(){
console._log.apply(this, arguments);
if (debugLog.length > MAX_MESSAGES) {
debugLog.shift();
}
var args = Array.prototype.slice.call(arguments);
var str = args.join(' ').replace(PHONE_REGEX, "+[REDACTED]$1");
debugLog.push(str);
};
console.get = function() {
return debugLog.join('\n');
};
console.post = function(log) {
if (log === undefined) {
log = console.get();
}
return new Promise(function(resolve) {
$.post('https://api.github.com/gists', textsecure.utils.jsonThing({
"files": { "debugLog.txt": { "content": log } }
})).then(function(response) {
console._log('Posted debug log to ', response.html_url);
resolve(response.html_url);
}).fail(resolve);
});
};
window.onerror = function(message, script, line, col, error) {
console.log(error);
};
}
})();