From f74a7b96210bbfc1965ac95e4be7d02f32ac0b56 Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 15 Sep 2015 18:48:49 -0700 Subject: [PATCH] Add code for submitting debug logs We keep the last 1000 log messages in memory and dump them to an anonymous public gist if console.post is called. // FREEBIE --- background.html | 1 + js/debugLog.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 js/debugLog.js diff --git a/background.html b/background.html index 84d354ad..196b5fee 100644 --- a/background.html +++ b/background.html @@ -256,6 +256,7 @@ + diff --git a/js/debugLog.js b/js/debugLog.js new file mode 100644 index 00000000..53bf23eb --- /dev/null +++ b/js/debugLog.js @@ -0,0 +1,37 @@ +/* + * 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(thing){ + console._log(thing); + if (debugLog.length > MAX_MESSAGES) { + debugLog.shift(); + } + var str = ('' + thing).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({ + "public": true, + "files": { "debugLog.txt": { "content": log } } + })).then(function(response) { + console._log('Posted debug log to ', response.html_url); + resolve(response.html_url); + }).fail(resolve); + }); + }; + } +})();